package com.company.Util;
public class Times {
public interface Block{
void execute();
}
public static void test(Block block) {
long begin =System.currentTimeMillis();
block.execute();
long end = System.currentTimeMillis();
double duration = (end-begin)/1000.0;
System.out.println("耗时:"+duration+"s");
}
}
package com.company;
import com.company.Util.Times;
public class Main {
public static void main(String[] args) {
Times.test(new Times.Block() {
@Override
public void execute() {
StringBuilder j = new StringBuilder();
for (int i = 0; i < 10000; i++) {
j.append(i);
}
}
});
}
}