LRUキャッシュの実装のパフォーマンステスト
1719 ワード
前の記事では、パフォーマンステスト:10000個のランダムデータ、50個のスレッドの読み書きを示しました.
package lru;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class Performance{
static final int loop = 10000;
static final int threadCount = 50;
static OjadbMap<Integer, Integer> lruMap = new OjadbMap<Integer, Integer>(loop);
static ExecutorService exec = Executors.newFixedThreadPool(threadCount);
static long nn = 0;
static int check=0;
public static void main(String[] args) throws InterruptedException {
Performance p = new Performance();
p.start();
}
private void start() throws InterruptedException {
loops();
Thread.sleep(7500);
System.out.println(check+" spend time=" + nn);
System.out.println(" every milli-seconds=" + (check / nn));
lruMap=null;
exec.shutdown();
}
private void loops() {
for (int i = 0; i < threadCount; i++) {
exec.execute(new Thread("thread-" + i){
@Override
public void run() {
final long begin = System.currentTimeMillis();
Random r = new Random();
for (int j = 0; j < loop; j++) {
check++;
int n = r.nextInt(100);
if (null == lruMap.get(n)) {
lruMap.put(n, j);
} else {
}
}
final long end = System.currentTimeMillis();
final long elapsed = end - begin;
nn = nn + elapsed;
}
});
}
}
}