Advertisement
Guest User

Benchmark results with local variable and primitive array

a guest
Apr 23rd, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 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.         Operation o1 = new Operation() {
  11.  
  12.             @Override
  13.             public void run() {
  14.                 int[] a = new int[] { 1, 2 };
  15.                 boolean b = a instanceof int[];
  16.             }
  17.  
  18.             @Override
  19.             public String getId() {
  20.                 return "a instanceof int[]";
  21.             }
  22.  
  23.         };
  24.         Operation o2 = new Operation() {
  25.  
  26.             @Override
  27.             public void run() {
  28.                 int[] a = new int[] { 1, 2 };
  29.                 boolean b = a.getClass().isArray();
  30.             }
  31.  
  32.             @Override
  33.             public String getId() {
  34.                 return "a.getClass().isArray()";
  35.             }
  36.  
  37.         };
  38.         Operation o3 = new Operation() {
  39.  
  40.             @Override
  41.             public void run() {
  42.                 int[] a = new int[] { 1, 2 };
  43.                 boolean b = a.getClass().getName().charAt(0) == '[';
  44.             }
  45.  
  46.             @Override
  47.             public String getId() {
  48.                 return "a.getClass().getName().charAt(0) == '['";
  49.             }
  50.  
  51.         };
  52.         Benchmark b = new Benchmark(o1, o2, o3);
  53.         b.setNestedLoopIterations(5000000);
  54.         b.setMainLoopIterations(100);
  55.         b.run();
  56.         for (Entry<String, Performance> e : b.getPerformances().entrySet()) {
  57.             System.out.println("{" + e.getKey() + "} spends " + e.getValue());
  58.         }
  59.     }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement