Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2013
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. package com.comphenix.testing;
  2.  
  3. import com.comphenix.testing.BlockChangeArray.BlockChange;
  4.  
  5. import com.google.caliper.Runner;
  6. import com.google.caliper.SimpleBenchmark;
  7.  
  8. /*
  9.  * RESULT:
  10.  *
  11.  *  0% Scenario{vm=java, trial=0, benchmark=Normal} 2,87 ns; ?=0,02 ns @ 3 trials
  12.  *  50% Scenario{vm=java, trial=0, benchmark=Recycle} 3,33 ns; ?=0,23 ns @ 10 trials
  13.  *  
  14.  *  benchmark   ns linear runtime
  15.  *     Normal 2,87 =========================
  16.  *    Recycle 3,33 ==============================
  17.  *  
  18.  *  vm: java
  19.  *  trial: 0
  20.  */
  21.  
  22. class Test {
  23.     public static class Benchmark extends SimpleBenchmark {
  24.         private BlockChangeArray array = new BlockChangeArray(100);
  25.        
  26.         public int timeNormal(int reps) {
  27.             for (int i = 0; i < reps; i++) {
  28.                 BlockChange change = array.getBlockChange(i % 100);
  29.                 change.setBlockID(change.getBlockID() + 1);
  30.             }
  31.             return array.getBlockChange(0).getBlockID();
  32.         }
  33.        
  34.         public int timeRecycle(int reps) {
  35.             BlockChange reused = null;
  36.            
  37.             for (int i = 0; i < reps; i++) {
  38.                 reused = array.getBlockChange(i % 100, reused);
  39.                 reused.setBlockID(reused.getBlockID() + 1);
  40.             }
  41.             return array.getBlockChange(0).getBlockID();
  42.         }
  43.     }
  44.    
  45.     public static void main(String[] args) throws Exception {
  46.         Runner.main(Benchmark.class, args);
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement