Tools to bench and compare different codes producing the same result.
You have to implements Benchamrkable for each code you want to bench.
public class Slow extends Benchmarkable {
@Override
public void execute(long id) {
int a = 0;
for (int i = 0; i < 1000; i++) {
a += i;
}
}
}
In the Main class, you have to call benchmarker.addBenchmarkable for each Benchmarkable you want to bench.
Example: We want to compare execution velocity between Fast and Slow Benchmarkables.
benchmarker.addBenchmarkable(new Fast());
benchmarker.addBenchmarkable(new Slow());
In the Main class, you have to call benchmarker.bench for each test you want to execute. For each execution the benchmarker will calculate the time elapsed.
Example: We want to execute benchmarkables 1 time, then 50 times.
benchmarker.bench(1);
benchmarker.bench(50);
Just run the main method in the Main class.
Look at the output console.
---------------------------------------
1 loops
Fast
-> 1746754 ns
Slow
-> 1558736 ns
Fast (per loop)
-> 1746754 ns
Slow (per loop)
-> 1558736 ns
---------------------------------------
50 loops
Fast
-> 316510 ns
Slow
-> 967180 ns
Fast (per loop)
-> 6330 ns
Slow (per loop)
-> 19343 ns
--------------------------------------------
Total time: 11283908 ns
If you want the Benchmarker do something more, feel free to tell me what you need/want.
You may also fork this repository, do the job in your own fork, and ask a pull request.