Closed
Description
I'm writing this as a guide on how to make contributed benchmarks "more valid" and actually measure what they are supposed to. Note that as of current state benchmarks in this repo don't follow them.
- make sure to benchmark for small collections(<4 elems), they are the most common
- make sure to include sizes which are not "magical" for your collection. E.g. Degrees of 2. I propose to standardise on those sizes:
0, 1, 2, 3, 4, 7, 8, 15, 16, 17, 39, 282, 73121, 7312102
. - Use
Blackhole.consume
instead of returning a value from a method - Use
Blackhole.consume
to ensure that data you are accessing is actually accessed - don't use
foreach
as a way to run multiple iterations of benchmark. Use a hand-written while cycle and@OperationsPerInvocation
, eg https://github.com/DarkDimius/DelayingArrays/blob/rewrite/src/main/scala/me/d_d/delaying/Benchmarks.scala#L151 - If you are accessing the same data in every benchmark iteration, eg.
list.head
, make sure to have a set-up run to ellide it from memory. This is hard to get right and this is why I recommend to not include such benchmarks. - If you are accessing random data, make sure not to use random number generator provided in Java. It's slow. You'll be benchmarking RNG instead of your collection. A good idea would be to pre-fill an array with indexes that you are going to access(suggested by @Ichoran).
- make sure you're not measuring boxing\string allocation. It may be slower than the actual operaion being performed in benchmark.
- best way to ensure this, read assembly resulting from JIT-ting your code;
If you want to get reliable numbers when running on your machine , make sure that you have:
- a physical machine. Getting reliable number in vitalized environment is hard;
- everything that can do some background computation disabled, including:
- cron;
- ntpd;
- OS updates, not only installation, but even checks for updates;
- web browsers\music
- filesystems and SSD drives can sometimes do operations that are similar to garbage collection in VM. Make sure not to use them(I recommend launching entire OS in ramdisk).
- cpu fixed to the same speed:
- disabled turbo-boost
- cpu scheduler fixed to a fixed frequency
- to ensure that cpu doesn't clockdown due to overheating, fix it to a lower frequency,
- disable hpet.
- absence of memory swapping.
Additions and suggestions are welcome.
Metadata
Metadata
Assignees
Labels
No labels