Riven,
Micro-benchmarking is like quantum phisycs:
observation is disturbed by measurement itself.
Hotspot compiler is known for having strange behaviour in
some cases.
I have slightly modified your code to make it more readable:
// New
{
long ts, te;
ts = System.nanoTime();
for (int k = 0; k < loops; k++)
calcNew(a, b, c);
te = System.nanoTime();
tNew[i] = te - ts;
}
// Pool
{
long ts, te;
ts = System.nanoTime();
for (int k = 0; k < loops; k++)
calcPool(a, b, c);
te = System.nanoTime();
tPool[i] = te - ts;
}
Results:
Java HotSpot(TM) Server VM (build 11.0-b09, mixed mode)
Typical tNew: [b]64800135[/b]
Typical tPool: [b]3851607[/b]
So I changed execution order inside Bench.main loop as follows :
// Pool
{
long ts, te;
ts = System.nanoTime();
for (int k = 0; k < loops; k++)
calcPool(a, b, c);
te = System.nanoTime();
tPool[i] = te - ts;
}
// New
{
long ts, te;
ts = System.nanoTime();
for (int k = 0; k < loops; k++)
calcNew(a, b, c);
te = System.nanoTime();
tNew[i] = te - ts;
}
and I’ve got
Java HotSpot(TM) Server VM (build 11.0-b09, mixed mode)
Typical tNew: [b]4922693[/b]
Typical tPool: [b]64387792[/b]
It seems that hotspot compiler doesn’t optimize first part of for loop.
Angelo