java
public interface CallBack {
void execute();
}
class TimeTest {
public static void getTime(CallBack callBack) {
long startTime = System.currentTimeMillis();
callBack.execute();
long endTime = System.currentTimeMillis();
System.out.println("执行时间为: " + (endTime - startTime));
}
}
public class GetTimeTest {
public void Test() throws InterruptedException {
Thread.sleep(1000);
}
public static void main(String[] args) {
TimeTest.getTime(() -> {
try {
new GetTimeTest().Test();
} catch (InterruptedException e) {
e.printStackTrace();
}
});
}
}
go
func TimeCost(start time.Time) {
terminal :=time.Since(start)
fmt.Println(terminal)
}
func Test() {
defer TimeCost(time.Now())
fmt.Println(RandomNumber(10,10,30))
fmt.Println(RandomNumber(5,100,200))
}