自己维护notEmptyWaitThreadCount计数

git-svn-id: http://code.alibabatech.com/svn/druid/trunk@713 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-09-10 12:58:02 +00:00
parent 449728843f
commit 90b14ec70b
3 changed files with 77 additions and 26 deletions
@@ -0,0 +1,45 @@
package com.alibaba.druid.benckmark;
import java.util.concurrent.atomic.AtomicInteger;
import junit.framework.TestCase;
public class TestAtomicPerformance extends TestCase {
public void test_0() throws Exception {
AtomicInteger count = new AtomicInteger();
for (int i = 0; i < 5; ++i) {
perf(count);
}
System.out.println();
for (int i = 0; i < 5; ++i) {
perf2(count);
}
}
private void perf(AtomicInteger count) {
long startMillis = System.currentTimeMillis();
count.set(0);
for (int i = 0; i < 1000 * 1000 * 100; ++i) {
int value = count.get();
count.compareAndSet(value, value + 1);
}
long millis = System.currentTimeMillis() - startMillis;
System.out.println("millis " + millis);
}
private void perf2(AtomicInteger count) {
long startMillis = System.currentTimeMillis();
count.set(0);
for (int i = 0; i < 1000 * 1000 * 100; ++i) {
int value = count.get();
count.weakCompareAndSet(value, value + 1);
}
long millis = System.currentTimeMillis() - startMillis;
System.out.println("weak millis " + millis);
}
}
@@ -62,7 +62,7 @@ public class TestIdle3_Concurrent_Starvation extends TestCase {
}
for (int i = 0; i < 1; ++i) {
final int threadCount = 5;
final int threadCount = 10;
concurrent(threadCount);
}