1 19 package bak.pcj.benchmark; 20 21 import bak.pcj.map.IntKeyMap; 22 import bak.pcj.map.IntKeyMapIterator; 23 24 32 public abstract class IntKeyMapBenchmark extends Benchmark { 33 34 private IntKeyMapFactory factory; 35 36 public IntKeyMapBenchmark(IntKeyMapFactory factory) { 37 this.factory = factory; 38 } 39 40 protected IntKeyMap create(int[] keys, Integer [] values) { 41 return factory.create(keys, values); 42 } 43 44 protected IntKeyMap create() { 45 return create(new int[]{}, new Integer []{}); 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 IntKeyMap c = create(dataSet.get(0), dataSet.getObjects(0)); 56 int[] l = dataSet.get(0); 57 Integer [] k = dataSet.getObjects(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 IntKeyMap c = create(dataSet.get(0), dataSet.getObjects(0)); 67 int[] l = dataSet.get(1); 68 Integer [] ll = dataSet.getObjects(1); 69 startTimer(); 70 for (int i = 0; i < l.length; i++) 71 c.put(l[i], ll[i]); 72 stopTimer(); 73 return l.length + " non-overwriting calls to put() with " + l.length + " mappings"; 74 } 75 76 public String benchmarkGetExisting(DataSet dataSet) { 77 IntKeyMap c = create(dataSet.get(0), dataSet.getObjects(0)); 78 int[] l = dataSet.get(0); 79 startTimer(); 80 for (int i = 0; i < l.length; i++) 81 c.get(l[i]); 82 stopTimer(); 83 return l.length + " successful calls to get() with " + c.size() + " mappings"; 84 } 85 86 public String benchmarkGetNonExisting(DataSet dataSet) { 87 IntKeyMap c = create(dataSet.get(0), dataSet.getObjects(0)); 88 int[] l = dataSet.get(1); 89 startTimer(); 90 for (int i = 0; i < l.length; i++) 91 c.get(l[i]); 92 stopTimer(); 93 return l.length + " unsuccessful calls to get() with " + c.size() + " mappings"; 94 } 95 96 public String benchmarkRemoveExisting(DataSet dataSet) { 97 IntKeyMap c = create(dataSet.get(0), dataSet.getObjects(0)); 98 int[] l = dataSet.get(0); 99 startTimer(); 100 for (int i = 0; i < l.length; i++) 101 c.remove(l[i]); 102 stopTimer(); 103 return l.length + " successful calls to remove() with " + l.length + " mappings"; 104 } 105 106 public String benchmarkRemoveNonExisting(DataSet dataSet) { 107 IntKeyMap c = create(dataSet.get(0), dataSet.getObjects(0)); 108 int[] l = dataSet.get(1); 109 startTimer(); 110 for (int i = 0; i < l.length; i++) 111 c.remove(l[i]); 112 stopTimer(); 113 return l.length + " unsuccessful calls to remove() with " + l.length + " mappings"; 114 } 115 116 public String benchmarkIterator(DataSet dataSet) { 117 IntKeyMap c = create(dataSet.get(0), dataSet.getObjects(0)); 118 startTimer(); 119 IntKeyMapIterator it = c.entries(); 120 while (it.hasNext()) { 121 it.next(); 122 it.getKey(); 123 it.getValue(); 124 } 125 stopTimer(); 126 return "Iteration over " + c.size() + " mappings"; 127 } 128 129 } | Popular Tags |