mih*_*jlv 2 java function timer
我func a(x, y z)
想要时间,有没有办法:
time = timeit( a(x,y,z) )
在java中,它会接受任何函数的时间.
喜欢:
long timeit(Object func){
long startTime = System.currentTimeMillis();
func(...);
return System.currentTimeMillis() - startTime;
}
Run Code Online (Sandbox Code Playgroud)
您需要Runnable
在public void run()
方法中将您的函数放在interface中.修改后的代码
public long timeit(Runnable func)
{
long startTime = System.currentTimeMillis();
func.run();
return System.currentTimeMillis() - startTime;
}
Run Code Online (Sandbox Code Playgroud)
功能:
public class MyFunction implements Runnable
{
@Override public void run() { System.out.println(); }
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
132 次 |
最近记录: |