浏览 1767 次
锁定老帖子 主题:LRU缓存的实现之性能测试
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-12-08
最后修改:2010-11-16
针对上一篇文章,这里给出性能测试: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; } }); } } }
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |