这里给出java测试代码
1.Stopwatch类的实现
public void start() {
this.startTime = System.currentTimeMillis();
}
public void stop() {
this.stopTime = System.currentTimeMillis();
}
//elaspsed time in milliseconds
public long getElapsedTime() {
long elapsed;
elapsed = (stopTime - startTime);
return elapsed;
}
}
2.测试工作类的实现
public double MulTest()
{
int count=10000*10000,i=0;
double sum=0.0;
for(i=1;i<count;i++)sum*=i;
return sum;
}
public double DivTest()
{
int count=10000*10000,i=0;
double sum=0.0;
for(i=1;i<count;i++)sum/=i;
return sum;
}
private long fib(long n)
{
if (n < 2)
return (1);
else
return (fib(n - 2) + fib(n - 1));
}
public double FibTest()
{
return (double)fib(30);
}
}
3.自动测试类
try
{
Class myclass = Class.forName("my.test.WorkClass");
Method mytest_fun = myclass.getMethod(itemname);
for(run_count=0;run_count<test_count;run_count++)
{
ret=0.0;
sw.start();
ret=(Double)mytest_fun.invoke(wc,null);
if(ret>0)sw.stop();
else sw.stop();
test_time+=sw.getElapsedTime();
}
}catch (Throwable e)
{
System.err.println(e);
}
String outstr="work cost average time(10)="+test_time/test_count;
System.out.println(outstr);
}
}
4.最后是主程序类
}
}