optimize the performance of existing code, such as inserting one by one = "batch insertion wants to have an intuitive comparison before and after VS optimization
so a unit test class is written specifically to time it as follows
@Test
public void foo(){
long start = System.currentTimeMillis();
service.foo();
long end = System.currentTimeMillis();
System.out.println("taken time(ms): "+(end-start));
}
but the execution time is different each time. The following is the time that has been executed three times in a row. I don"t know which one to choose
532ms 717ms 520ms
I wonder if there is a tool like timeit in Python as follows
>>> timeit.timeit(lambda:sleep(0.1), number=10)
1.02257220899628
can be timed automatically and can explicitly specify how many times to run
@Timeit(number=10)
@Test
public void foo(){
service.foo();
}