Permalink
Browse files

Add a random performance benchmark for kicks

  • Loading branch information...
1 parent 00b5db4 commit 4b6393ad9e3a56d0a3e24101195df3872e1b81d7 @mikera committed Dec 11, 2012
Showing with 43 additions and 0 deletions.
  1. +43 −0 src/test/java/mikera/performance/PerformanceBenchmark.java
@@ -0,0 +1,43 @@
+package mikera.performance;
+
+import com.google.caliper.Runner;
+import com.google.caliper.SimpleBenchmark;
+
+
+public class PerformanceBenchmark extends SimpleBenchmark {
+ public long r=0;
+
+ public void timeOriginal(int runs) {
+ for (int i=0; i<runs; i++) {
+ long input = i;
+ long result=
+ (input & 0x000000FF) |
+ (input & 0x0000FF00) << 8 |
+ (input & 0x00FF0000) << 16 |
+ (input & 0xFF000000) << 24;
+ r=result;
+ }
+ }
+
+ public void timeImproved(int runs) {
+ for (int i=0; i<runs; i++) {
+ long input = i;
+ long a = (input | (input << 16));
+ long result = (a & 0xFF000000FFL) + ((a & 0xFF000000FF00L) <<8);
+ r=result;
+ }
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ new PerformanceBenchmark().run();
+ }
+
+ private void run() {
+ Runner runner=new Runner();
+ runner.run(new String[] {this.getClass().getCanonicalName()});
+ }
+
+}

0 comments on commit 4b6393a

Please sign in to comment.