Advertisement
Guest User

Benchmark results

a guest
Apr 23rd, 2013
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1. import java.util.Map.Entry;
  2.  
  3. import Benchmark;
  4. import Benchmark.Operation;
  5. import Benchmark.Performance;
  6.  
  7. public class Main {
  8.  
  9.     public static void main(String[] args) throws Exception {
  10.         final String[] s = new String[] { "foo", "bar" };
  11.         Operation o1 = new Operation() {
  12.  
  13.             @Override
  14.             public void run() {
  15.                 boolean b = s instanceof Object[];
  16.             }
  17.  
  18.             @Override
  19.             public String getId() {
  20.                 return "s instanceof Object[]";
  21.             }
  22.  
  23.         };
  24.         Operation o2 = new Operation() {
  25.  
  26.             @Override
  27.             public void run() {
  28.                 boolean b = s.getClass().isArray();
  29.             }
  30.  
  31.             @Override
  32.             public String getId() {
  33.                 return "s.getClass().isArray()";
  34.             }
  35.  
  36.         };
  37.         Operation o3 = new Operation() {
  38.  
  39.             @Override
  40.             public void run() {
  41.                 boolean b = s.getClass().getName().charAt(0) == '[';
  42.             }
  43.  
  44.             @Override
  45.             public String getId() {
  46.                 return "s.getClass().getName().charAt(0) == '['";
  47.             }
  48.  
  49.         };
  50.         Benchmark b = new Benchmark(o1, o2, o3);
  51.         b.setNestedLoopIterations(5000000);
  52.         b.setMainLoopIterations(100);
  53.         b.run();
  54.         for (Entry<String, Performance> e : b.getPerformances().entrySet()) {
  55.             System.out.println("{" + e.getKey() + "} spends " + e.getValue());
  56.         }
  57.     }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement