Open JakubVanek opened 6 years ago
Hmmm... inventing it on my own is a little bit too complicated. Suppose we have this code:
float a = 0x88888888p0f;
float b = 0x11111111p0f;
float c = 0f;
start = System.nanoTime();
for (int i = 0; i < count; i++)
c = (float)(a - b);
end = System.nanoTime();
The compiler might be clever enough to figure out that a
and b
don't change and might cache the result.
Well, let's make a
and b
volatile.
Now we have the problem of memory access jitter. I don't know the bytecode, but it might have something like load_variable
, load_constant
, tested_op
and store_variable
ops.
On each loop, we are doing this:
load_variable to:reg0 from:mem_a
load_variable to:reg1 from:mem_b
tested_op to:reg2 from:reg0 from:reg1
store_variable to:mem_c from:reg2
But we want to measure only this:
tested_op from:reg0 from:reg1 to:reg2
I'm afraid this can't be solved even by JMH.
Experiment with JMH could be very nice for the project.
Do you have multiple bricks to experiment?
Hi,
no, I have only one education set and it's borrowed from FEE CTU.
Jakub
If you could get another one by Science purposes, we could experiment with RMI to synchronise java processes located in different JVMs.
Good night
Juan Antonio
Hi,
I've tried using
System.nanoTime
and I still get negative durations on my machine (OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode
):The compiler (source → bytecode or bytecode → x86) must be somehow reordering the program flow.
The same thing happens on the brick with OpenJDK 9, with the exception that it's in the float benchmark.
Well, I know of two possible solutions. One is to try to isolate benchmarks to their own functions and somehow limit the optimizer, the second is to use Java Microbenchmark Harness - I've read on StackOverflow that it is the recommended way of running tests like this.
Jakub Vaněk