BAEL-4686: Corrected the test
This commit is contained in:
parent
61f4eb62a7
commit
bd6bc03c93
|
@ -15,7 +15,7 @@ public class ConcurrentHashMapVsSynchronizedMapPerformanceTest {
|
||||||
|
|
||||||
public final static int THREAD_POOL_SIZE = 5;
|
public final static int THREAD_POOL_SIZE = 5;
|
||||||
public final static int TEST_ITERATIONS = 5;
|
public final static int TEST_ITERATIONS = 5;
|
||||||
public final static int TEST_NO_ITEMS = 500000;
|
public final static int TEST_NO_ITEMS = 10000;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void randomReadAndWritePerformaceTest_ConcurrentHashMap_faster()
|
public void randomReadAndWritePerformaceTest_ConcurrentHashMap_faster()
|
||||||
|
@ -40,6 +40,28 @@ public class ConcurrentHashMapVsSynchronizedMapPerformanceTest {
|
||||||
Assert.assertTrue(avgTimeForSynchronizedMap > avgTimeForConcurrentHashMap);
|
Assert.assertTrue(avgTimeForSynchronizedMap > avgTimeForConcurrentHashMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long performReadAndWriteTest(final Map<String, Integer> map)
|
||||||
|
throws InterruptedException {
|
||||||
|
long startTime = System.nanoTime();
|
||||||
|
ExecutorService exectures = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
|
||||||
|
for (int j = 0; j < THREAD_POOL_SIZE; j++) {
|
||||||
|
exectures.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (int i = 0; i < TEST_NO_ITEMS; i++) {
|
||||||
|
Integer randNumber = (int) Math.ceil(Math.random() * TEST_NO_ITEMS);
|
||||||
|
map.get(String.valueOf(randNumber));
|
||||||
|
map.put(String.valueOf(randNumber), randNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exectures.shutdown();
|
||||||
|
exectures.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
|
||||||
|
long entTime = System.nanoTime();
|
||||||
|
return (entTime - startTime) / 1000000L;
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void randomWritePerformaceTest_ConcurrentHashMap_faster() throws InterruptedException {
|
public void randomWritePerformaceTest_ConcurrentHashMap_faster() throws InterruptedException {
|
||||||
// For synchronizedMap
|
// For synchronizedMap
|
||||||
|
@ -62,6 +84,26 @@ public class ConcurrentHashMapVsSynchronizedMapPerformanceTest {
|
||||||
Assert.assertTrue(avgTimeForSynchronizedMap > avgTimeForConcurrentHashMap);
|
Assert.assertTrue(avgTimeForSynchronizedMap > avgTimeForConcurrentHashMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long performWriteTest(final Map<String, Integer> map) throws InterruptedException {
|
||||||
|
long startTime = System.nanoTime();
|
||||||
|
ExecutorService exectures = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
|
||||||
|
for (int j = 0; j < THREAD_POOL_SIZE; j++) {
|
||||||
|
exectures.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (int i = 0; i < TEST_NO_ITEMS; i++) {
|
||||||
|
Integer randNumber = (int) Math.ceil(Math.random() * TEST_NO_ITEMS);
|
||||||
|
map.put(String.valueOf(randNumber), randNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exectures.shutdown();
|
||||||
|
exectures.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
|
||||||
|
long entTime = System.nanoTime();
|
||||||
|
return (entTime - startTime) / 1000000L;
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void randomReadPerformaceTest_ConcurrentHashMap_faster() throws InterruptedException {
|
public void randomReadPerformaceTest_ConcurrentHashMap_faster() throws InterruptedException {
|
||||||
|
|
||||||
|
@ -94,48 +136,6 @@ public class ConcurrentHashMapVsSynchronizedMapPerformanceTest {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
private long performWriteTest(final Map<String, Integer> map) throws InterruptedException {
|
|
||||||
long startTime = System.nanoTime();
|
|
||||||
ExecutorService exectures = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
|
|
||||||
for (int j = 0; j < THREAD_POOL_SIZE; j++) {
|
|
||||||
exectures.execute(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
for (int i = 0; i < TEST_NO_ITEMS; i++) {
|
|
||||||
Integer randNumber = (int) Math.ceil(Math.random() * TEST_NO_ITEMS);
|
|
||||||
map.put(String.valueOf(randNumber), randNumber);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
exectures.shutdown();
|
|
||||||
exectures.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
|
|
||||||
long entTime = System.nanoTime();
|
|
||||||
return (entTime - startTime) / 1000000L;
|
|
||||||
}
|
|
||||||
|
|
||||||
private long performReadAndWriteTest(final Map<String, Integer> map)
|
|
||||||
throws InterruptedException {
|
|
||||||
long startTime = System.nanoTime();
|
|
||||||
ExecutorService exectures = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
|
|
||||||
for (int j = 0; j < THREAD_POOL_SIZE; j++) {
|
|
||||||
exectures.execute(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
for (int i = 0; i < TEST_NO_ITEMS; i++) {
|
|
||||||
Integer randNumber = (int) Math.ceil(Math.random() * TEST_NO_ITEMS);
|
|
||||||
map.get(String.valueOf(randNumber));
|
|
||||||
map.put(String.valueOf(randNumber), randNumber);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
exectures.shutdown();
|
|
||||||
exectures.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
|
|
||||||
long entTime = System.nanoTime();
|
|
||||||
return (entTime - startTime) / 1000000L;
|
|
||||||
}
|
|
||||||
|
|
||||||
private long performReadTest(final Map<String, Integer> map) throws InterruptedException {
|
private long performReadTest(final Map<String, Integer> map) throws InterruptedException {
|
||||||
long startTime = System.nanoTime();
|
long startTime = System.nanoTime();
|
||||||
ExecutorService exectures = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
|
ExecutorService exectures = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
|
||||||
|
|
Loading…
Reference in New Issue