Swap should be better done native?
Martin Buchholz
martinrb at google.com
Wed Mar 31 15:49:03 PDT 2010
Alan, please file a bug and review this change.
Synopsis: Optimize java/nio/Bits.java
Description:
Use intrinsified reverseBytes operation; elide no-op constructs
So I have a proposed patch:
http://cr.openjdk.java.net/~martin/webrevs/openjdk7/nioBits.java/
I was surprised that I had written a benchmark for this years ago,
and also surprised how much faster the swapping got by using
the intrinsified methods
Below are before/after benchmark results:
==> javac -Xlint:all SwapMicroBenchmark.java
==> java -server -esa -ea SwapMicroBenchmark
Method Millis Ratio
swap char BIG_ENDIAN 84 1.000
swap char LITTLE_ENDIAN 49 0.585
swap short BIG_ENDIAN 97 1.153
swap short LITTLE_ENDIAN 49 0.589
swap int BIG_ENDIAN 70 0.834
swap int LITTLE_ENDIAN 25 0.308
swap long BIG_ENDIAN 77 0.913
swap long LITTLE_ENDIAN 10 0.125
applying nioBits.java
now at: nioBits.java
Recompiled:
/usr/local/google/home/martin/ws/upstream/src/share/classes/java/nio/Bits.java
==> javac -Xlint:all SwapMicroBenchmark.java
==> java -server -esa -ea SwapMicroBenchmark
Method Millis Ratio
swap char BIG_ENDIAN 67 1.000
swap char LITTLE_ENDIAN 50 0.741
swap short BIG_ENDIAN 68 1.010
swap short LITTLE_ENDIAN 50 0.739
swap int BIG_ENDIAN 20 0.306
swap int LITTLE_ENDIAN 26 0.393
swap long BIG_ENDIAN 13 0.202
swap long LITTLE_ENDIAN 10 0.157
Martin
More information about the nio-discuss
mailing list