利用钩子函数测试某段代码的执行效率
2017-08-19 13:23
239 查看
后期可以利用动态代理切入,或者aop切入
代码如下:
代码如下:
package com.callback; /** * main方法测试 * @author tiger * */ public class CountTime { public static void main(String[] args) { Test test = new Test(); test.getTime(); } } /** * 测试类 * @author tiger * */ class Test extends GetTime{ @Override public void userCode() { for (int i = 0; i < 12000; i++) { int a = i+i; System.out.println(a); //...code.... } } } /** * 运行时间封装抽象类 * @author tiger * */ abstract class GetTime{ public final void getTime(){ long start=System.currentTimeMillis(); //1s=1000ms userCode();//钩子、bushi回调 long stop=System.currentTimeMillis(); System.out.println("本程序共花费了:"+(stop-start)+"毫秒"); } public abstract void userCode(); }
相关文章推荐
- 利用函数的惰性载入提高javascript代码执行效率
- microtime() 测试代码执行时间,提高编码效率
- 用 console.time()和 console.timeEnd() 测试你的 javascript 代码执行效率
- c# 计算程序执行时间,计算一段代码执行所用的时间,测试效率
- 利用c模块代码,提升python代码执行效率
- net 代码执行效率绝对测试代码
- python中使用time模块计算代码执行效率的精度测试
- 使用POCO库测试代码执行效率
- 利用StopWatch来监视代码执行效率
- C#测试代码执行效率的3种方式
- [心得] 用FlasCC编译c++代码为SWC执行效率测试
- 测试代码执行效率的几种方法比较
- python中使用time模块计算代码执行效率的精度测试(转)
- 如何快速测试代码的执行效率
- 如何测试sql语句性能,提高执行效率
- 浅谈代码的执行效率(1):算法是关键
- SQL语句执行效率及性能测试
- 大数据量分页存储过程效率测试附代码
- (转)代码执行的效率