1919import java .text .NumberFormat ;
2020import java .util .Date ;
2121
22- import com .javadocmd .simplelatlng .Geohasher ;
23- import com .javadocmd .simplelatlng .LatLng ;
24- import com .javadocmd .simplelatlng .LatLngTool ;
2522import com .javadocmd .simplelatlng .util .LengthUnit ;
2623import com .javadocmd .simplelatlng .window .CircularWindow ;
2724import com .javadocmd .simplelatlng .window .RectangularWindow ;
2825
29-
3026/**
3127 * Basic benchmarking test. Repeats the critical functions
3228 * a bunch of times and reports how long that took. Also
@@ -51,6 +47,7 @@ public static void main(String[] args) {
5147 p .profileRectangularWindow ();
5248 p .profileCircularWindow ();
5349 p .profileGeohasher ();
50+ p .profileHashCode ();
5451 }
5552
5653 private LatLng [] points ;
@@ -108,14 +105,19 @@ private void profileGeohasher() {
108105
109106 System .out .printf ("Geohashed and decoded in %s ms.\n " , integer .format (end .getTime ()
110107 - start .getTime ()));
108+ }
111109
112- start = new Date ();
113- for (int i = 0 ; i < points .length ; i ++) {
114- points [i ].hashCode ();
110+ private void profileHashCode () {
111+ // Repeat 5 times in hopes of detecting a caching benefit if any exists.
112+ Date start = new Date ();
113+ for (int j = 0 ; j < 5 ; j ++) {
114+ for (int i = 0 ; i < points .length ; i ++) {
115+ points [i ].hashCode ();
116+ }
115117 }
116- end = new Date ();
118+ Date end = new Date ();
117119
118- System .out .printf ("hashCode() in %s ms.\n " , integer .format (end .getTime ()
120+ System .out .printf ("hashCode() 5x in %s ms.\n " , integer .format (end .getTime ()
119121 - start .getTime ()));
120122 }
121123
0 commit comments