Factorize common benchmark code.
Probably should be in a library and used between all benchmarks.