BlackHole.consumeCPU
Ruslan Cheremin
cheremin at gmail.com
Tue Dec 3 10:26:57 PST 2013
consumeCPU(0) supposed to consume nothing. But in my version (1.0-snapshot?)
public static volatile long consumedCPU = 42;
public static void consumeCPU(long tokens) {
// randomize start so that JIT could not memoize;
long t = consumedCPU;
for (long i = 0; i < tokens; i++) {
t += (t * 0x5DEECE66DL + 0xBL) & (0xFFFFFFFFFFFFL);
}
if (t == 42) {
consumedCPU += t;
}
}
Clearly, first call _will_ do the write. It is not a big deal, usually
covered by warmup, but could shift short benchmarks a little. Doesn't 43 a
better choice for initial value? :)
More information about the jmh-dev
mailing list