1 19 package bak.pcj.benchmark; 20 21 import bak.pcj.map.IntKeyIntMap; 22 import bak.pcj.map.IntKeyIntMapIterator; 23 24 32 public abstract class IntKeyIntMapBenchmark extends Benchmark { 33 34 private IntKeyIntMapFactory factory; 35 36 public IntKeyIntMapBenchmark(IntKeyIntMapFactory factory) { 37 this.factory = factory; 38 } 39 40 protected IntKeyIntMap create(int[] keys, int[] values) { 41 return factory.create(keys, values); 42 } 43 44 protected IntKeyIntMap create() { 45 return create(new int[]{}, new int[]{}); 46 } 47 48 public String getClassId() { 49 Object v = create(); 50 String name = v.getClass().getName(); 51 return name; 52 } 53 54 public String benchmarkPutExisting(DataSet dataSet) { 55 IntKeyIntMap c = create(dataSet.get(0), dataSet.get(0)); 56 int[] l = dataSet.get(0); 57 int[] k = dataSet.get(1); 58 startTimer(); 59 for (int i = 0; i < l.length; i++) 60 c.put(l[i], k[i]); 61 stopTimer(); 62 return l.length + " overwriting calls to put() with " + l.length + " mappings"; 63 } 64 65 public String benchmarkPutNonExisting(DataSet dataSet) { 66 IntKeyIntMap c = create(dataSet.get(0), dataSet.get(0)); 67 int[] l = dataSet.get(1); 68 startTimer(); 69 for (int i = 0; i < l.length; i++) 70 c.put(l[i], l[i]); 71 stopTimer(); 72 return l.length + " non-overwriting calls to put() with " + l.length + " mappings"; 73 } 74 75 public String benchmarkGetExisting(DataSet dataSet) { 76 IntKeyIntMap c = create(dataSet.get(0), dataSet.get(0)); 77 int[] l = dataSet.get(0); 78 startTimer(); 79 for (int i = 0; i < l.length; i++) 80 c.get(l[i]); 81 stopTimer(); 82 return l.length + " successful calls to get() with " + c.size() + " mappings"; 83 } 84 85 public String benchmarkGetNonExisting(DataSet dataSet) { 86 IntKeyIntMap c = create(dataSet.get(0), dataSet.get(0)); 87 int[] l = dataSet.get(1); 88 startTimer(); 89 for (int i = 0; i < l.length; i++) 90 c.get(l[i]); 91 stopTimer(); 92 return l.length + " unsuccessful calls to get() with " + c.size() + " mappings"; 93 } 94 95 public String benchmarkRemoveExisting(DataSet dataSet) { 96 IntKeyIntMap c = create(dataSet.get(0), dataSet.get(0)); 97 int[] l = dataSet.get(0); 98 startTimer(); 99 for (int i = 0; i < l.length; i++) 100 c.remove(l[i]); 101 stopTimer(); 102 return l.length + " successful calls to remove() with " + l.length + " mappings"; 103 } 104 105 public String benchmarkRemoveNonExisting(DataSet dataSet) { 106 IntKeyIntMap c = create(dataSet.get(0), dataSet.get(0)); 107 int[] l = dataSet.get(1); 108 startTimer(); 109 for (int i = 0; i < l.length; i++) 110 c.remove(l[i]); 111 stopTimer(); 112 return l.length + " unsuccessful calls to remove() with " + l.length + " mappings"; 113 } 114 115 public String benchmarkIterator(DataSet dataSet) { 116 IntKeyIntMap c = create(dataSet.get(0), dataSet.get(0)); 117 startTimer(); 118 IntKeyIntMapIterator it = c.entries(); 119 while (it.hasNext()) { 120 it.next(); 121 it.getKey(); 122 it.getValue(); 123 } 124 stopTimer(); 125 return "Iteration over " + c.size() + " mappings"; 126 } 127 128 } | Popular Tags |