各位帮帮忙.如何写一个能测试HashSet查找速度的程序(可通过不同的负载因子得到不同的的速度)
解决方案 »
- 请问java的用途?
- Spring声明式事务中如何管理Session
- 初学无知:定时刷新问题
- maven的plugin中,java的annotation写法是: @parameter expression="${project.build.directory}",这种语法怎么回事?求语法的参考指南
- applet如何访问自己所在包的资源?
- HELP,HELP,HELP!!!!!!!!!!!!!!!
- run()方法要有start()后才能运行吧
- 大散分:EJB第一次运行,发布成功.哈哈.
- 如何解决swing控件在IE中汉字显示十分不美观的问题?
- 利用Mysql数据库账户登录注册以及java网络编程和图形界面写的多人聊天室!
- 关于抽象类的一个简单问题~~
- 请写出下面代码的输出结果(13)
// Demonstrates performance differences in Maps.
// {Args: 500}
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
import java.util.*;
import com.bruceeckel.util.*;public class MapPerformance {
private static int reps = 50000;
private abstract static class Tester {
String name;
Tester(String name) { this.name = name; }
abstract void test(Map m, int size);
}
private static Tester[] tests = {
new Tester("put") {
void test(Map m, int size) {
for(int i = 0; i < reps; i++) {
m.clear();
Collections2.fill(m,
Collections2.geography.reset(), size);
}
}
},
new Tester("get") {
void test(Map m, int size) {
for(int i = 0; i < reps; i++)
for(int j = 0; j < size; j++)
m.get(Integer.toString(j));
}
},
new Tester("iteration") {
void test(Map m, int size) {
for(int i = 0; i < reps * 10; i++) {
Iterator it = m.entrySet().iterator();
while(it.hasNext())
it.next();
}
}
},
};
public static void test(Map m, int size) {
// Strip qualifiers from class name:
System.out.println("Testing " +
m.getClass().getName().replaceAll("\\w+\\.", "") +
" size " + size);
Collections2.fill(m,
Collections2.geography.reset(), size);
for(int i = 0; i < tests.length; i++) {
System.out.print(tests[i].name);
long t1 = System.currentTimeMillis();
tests[i].test(m, size);
long t2 = System.currentTimeMillis();
System.out.println(": " +
((double)(t2 - t1)/(double)size));
}
}
public static void main(String[] args) {
// Choose a different number of
// repetitions via the command line:
if(args.length > 0)
reps = Integer.parseInt(args[0]);
System.out.println(reps + " repetitions");
// Small:
test(new TreeMap(), 10);
test(new HashMap(), 10);
test(new LinkedHashMap(), 10);
test(new IdentityHashMap(), 10);
test(new WeakHashMap(), 10);
test(new Hashtable(), 10);
// Medium:
test(new TreeMap(), 100);
test(new HashMap(), 100);
test(new LinkedHashMap(), 100);
test(new IdentityHashMap(), 100);
test(new WeakHashMap(), 100);
test(new Hashtable(), 100);
// Large:
test(new TreeMap(), 1000);
test(new HashMap(), 1000);
test(new LinkedHashMap(), 1000);
test(new IdentityHashMap(), 1000);
test(new WeakHashMap(), 1000);
test(new Hashtable(), 1000);
}
}
基本就这样测试了,自己改改吧,