Currently I´m testing the time it takes to execute 2 static Java methods. Both Are 90% identicyl. The difference is one method is using a interface to communicate with a other class. The second method calls the class as given parameter.
There a simple example :
System.out.println(callBackTest());
System.out.println(directCallTest());
Both methods generate new classes. The wierd part is that the first mehtod return a useable duration in ms and the second not. It´s always 1 ms. When I comment out the first call the seconds call return a useable value.
Even wierder is the fact when i run them in a loop and sum the durations. Every first call return a usable value but other just return 1 ms.
for (int i = 0; i < 20; i++) {
testo t = new testo();
duration += t.callBackTest();
System.out.println(duration);
}
System.out
.println("CallBackTest. Took " + (duration / amountTest) + " in average for " + amountTest + " Tests");
duration = 0;
for (int i = 0; i < 20; i++) {
testo t = new testo();
duration += t.directCallTest();
System.out.println(duration);
}
System.out.println("DirectTest. Took " + (duration / amountTest) + " in average for " + amountTest + " Tests");
To sum Up this loop: 1. [method1] call = ~1300ms 2. [method1] call = ~1301ms 3. [method1] call = ~1302ms 4. [method1] call = ~1303ms ...
- [method2] call = ~1ms
- [method2] call = ~2ms
- [method2] call = ~3ms
- [method2] call = ~4ms ...
Btw. using the Spring Tool Stuite.
I´m super confused. Anyone a quick idea?