Let's now run a few tests and compare them. First, we run the following test method:
@Benchmark
@BenchmarkMode(Mode.All)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void testTheMethod0() {
int res = 0;
for(int i = 0; i < 1000; i++){
int n = i * i;
if (n != 0 && n % 250_000 == 0) {
res += n;
}
}
}
As you can see, we have requested to measure all the performance characteristics and to use nanoseconds while presenting the results. On our system, the test execution took around 20 minutes and the final results summary looked like this:
Let's now change the test as follows:
@Benchmark
@BenchmarkMode(Mode.All)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void testTheMethod1() {
SomeClass someClass = new SomeClass();
int i = 1000;
int s = 250_000;
someClass.someMethod(i, s);
}
If we run the testTheMethod1...