Mat*_*ias 3 profiler groovy annotations
我正在为基于Groovy的应用程序编写某种分析器.为此,我感兴趣的是在各种类方法中花费了多少处理时间.
现在,通过获取方法调用的开始和结束时间,可以简单地测量每种方法中花费的纳秒数.然而,这感觉很笨,我不想花时间"外"的方法(例如在通话之前和之后).我宁愿在班级内部测量时间,也不想通过开始和结束时间"手动",而是"自动",如果可能的话.
所以我的问题是:测量在类的各种方法中花费的时间最好,最Groovy的方法是什么?也许通过注释?
Groovy附带BenchmarkInterceptor:
拦截器,用于在调用之前和之后注册每个方法调用的时间戳.时间戳存储在内部,可以通过使用
Run Code Online (Sandbox Code Playgroud)getCalls()和
Run Code Online (Sandbox Code Playgroud)statistic()API.
用法示例:
Run Code Online (Sandbox Code Playgroud)def proxy = ProxyMetaClass.getInstance(ArrayList.class) proxy.interceptor = new BenchmarkInterceptor() proxy.use { def list = (0..10000).collect{ it } 4.times { list.size() } 4000.times { list.set(it, it+1) } } proxy.interceptor.statistic()其中产生以下输出:
Run Code Online (Sandbox Code Playgroud)[[size, 4, 0], [set, 4000, 21]]
| 归档时间: |
|
| 查看次数: |
681 次 |
| 最近记录: |