Code review request for 6908131 Pure Java implementations of StrictMath.floor(double) &StrictMath.ceil(double)
Dmitry Nadezhin
Dmitry.Nadezhin at Sun.COM
Fri Jan 29 08:59:25 UTC 2010
Martin, Thank you for the answer.
I found your benchmark in "jdk/test/java/util/ArrayList".
Also I see an example of microbenchmark included in the post to
core-libs-dev:
http://mail.openjdk.java.net/pipermail/core-libs-dev/2009-November/003226.html
.
Its nice to keep such microbenchmarks in jdk/tests. When there are
variants of method implementation,
the choice of fastest method is not forever. The choice can change later
after optimizations in HotSpot.
For example, floor and ceil results on pattern3 = { 0.1, -0.1, 1e4+0.1,
-1e4-0.1, 1e8+0.1, -1e8-0.1, 1e12+0.1, -1e12-0.1, (1L<<52)/1.1,
-(1L<<52)/1.1};
jdk1.5.0_21/bin/java -d32 -server
empty took 1,67 nsec
Math.ceil took 65,53 nsec
Math.floor took 66,62 nsec
StrictMath.ceil took 67,21 nsec
StrictMath.floor took 66,04 nsec
FloorCeilDarcy.ceil took 24,22 nsec
FloorCeilDarcy.floor took 23,36 nsec
FloorCeilHain.ceil took 97,61 nsec
FloorCeilHain.floor took 100,56 nsec
jdk1.5.0_21/bin/java -d64 -server
empty took 1,67 nsec
Math.ceil took 33,53 nsec
Math.floor took 33,54 nsec
StrictMath.ceil took 33,53 nsec
StrictMath.floor took 33,54 nsec
FloorCeilDarcy.ceil took 8,18 nsec
FloorCeilDarcy.floor took 16,96 nsec
FloorCeilHain.ceil took 20,39 nsec
FloorCeilHain.floor took 19,92 nsec
jdk1.7.0_b79/bin/java -d32 -server
empty took 1,67 nsec
Math.ceil took 15,74 nsec
Math.floor took 14,70 nsec
StrictMath.ceil took 15,76 nsec
StrictMath.floor took 14,70 nsec
FloorCeilDarcy.ceil took 15,88 nsec
FloorCeilDarcy.floor took 14,98 nsec
FloorCeilHain.ceil took 12,27 nsec
FloorCeilHain.floor took 10,38 nsec
jdk1.7.0_b79/bin/java -d64 -server
empty took 1,67 nsec
Math.ceil took 7,66 nsec
Math.floor took 7,81 nsec
StrictMath.ceil took 7,65 nsec
StrictMath.floor took 7,80 nsec
FloorCeilDarcy.ceil took 7,62 nsec
FloorCeilDarcy.floor took 7,80 nsec
FloorCeilHain.ceil took 12,65 nsec
FloorCeilHain.floor took 11,15 nsec
On JDK-1.5, Darcy's implementation was much faster than Hain's.
On JDK-1.7 -d32 -server, Hain's implementation is faster than Darcy's.
Perhaps implementation which are not the best choice now may become the
best choice later.
Perhaps alternative implementation should be stored somewhere too.
This maybe a project in OpenJdk or a subproject of other project.
I shall write something about it in the next message with a new subject.
-Dima
More information about the core-libs-dev
mailing list