예제 #1
0
 @Test
 public void testCurrentHashMap() {
   final Map<Integer, Integer> hash = new ConcurrentHashMap<Integer, Integer>();
   Nano.bench()
       .measurements(measurements)
       .threads(threads)
       .measure(
           "concurrent-hashmap",
           new Runnable() {
             public void run() {
               Random random = new Random(10000);
               for (int i = 0; i < 1000; i++) {
                 hash.put(i, i);
                 if (i % 2 == 0) {
                   for (int j = 0; j < 3; j++) {
                     hash.get(random.nextInt());
                   }
                 }
               }
             }
           });
 }
예제 #2
0
 @Test
 public void testSyncHashMap() {
   final Map<Integer, Integer> hash = Collections.synchronizedMap(new HashMap<Integer, Integer>());
   Nano.bench()
       .measurements(measurements)
       .threads(threads)
       .measure(
           "sync-hashmap",
           new Runnable() {
             public void run() {
               Random random = new Random(10000);
               for (int i = 0; i < 1000; i++) {
                 hash.put(i, i);
                 if (i % 2 == 0) {
                   for (int j = 0; j < 3; j++) {
                     hash.get(random.nextInt());
                   }
                 }
               }
             }
           });
 }