Name: krC82822 Date: 07/31/2001
orig synopsis: "java.util.Arrays.binarySearch() function can easily be sped up by approx 40%"
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
The binary search java.util.Arrays.binarySearch() is much slower than it needs
to be. For JDK 1.3.0 on win2000 (and possibly other platforms) using "/2"
instead of ">>1" is approximately 40% slower.
All that needs to be done to boost speed is to change the following line from
this:
int mid =(low + high)/2;
to this:
int mid =(low + high)>>1;
in the few places it occurs in java.util.Arrays.java
Better yet, the java compiler should recognise this as a standard optimisation
and do it whenever possible.
(Review ID: 129120)
======================================================================