#-*- coding: UTF-8 -*-#-------------------------------------------------------------------------------# Name: ģ��1# Purpose:## Author: Administrator## Created: 07-11-2012# Copyright: (c) Administrator 2012# Licence:#-------------------------------------------------------------------------------from springpython.context import ApplicationContextfrom springpython.config import PythonConfigfrom springpython.aop import *import timeclass PerformanceInterceptor(MethodInterceptor): def invoke(self, invocation): start = time.time() results = invocation.proceed() stop = time.time() print "Method took %2f seconds" % (stop - start) return resultsclass WikiService: def AddWhileInt(self, a, b): result = a+b total = 10000000 while(total): total-=1 result+=1 return result def AddWhileTrue(self, a, b): result = a+b total = 10000000 while(total>0): total-=1 result+=1 return resultclass IocPythonContainer(PythonConfig): def __init__(self): super(IocPythonContainer, self).__init__() def PerformanceAdvisor(self): return RegexpMethodPointcutAdvisor( advice = [PerformanceInterceptor()], patterns = [".*.*"] ) def WikiService(self): return ProxyFactoryObject( target = WikiService(), interceptors =[self.PerformanceAdvisor()] ) def main(): container = IocPythonContainer() service = container.WikiService() result = service.AddWhileInt(100, 20) print result result = service.AddWhileTrue(100, 20) print resultif __name__ == '__main__': main()