Tools that Java unit tests have no automatic timing and can explicitly specify how many times to run are similar to timeit in Python

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();
}
Mar.07,2021
  • Java unit test

    1. If I have a class A with four methods of addition, deletion, modification and query, do I have to write all four methods in one test class when I write a unit test? 2. If written in a test class, then : : : : 3. Then inserting data in step 2 can b...

    Nov.19,2021
Menu