求..高手一个HashSet测试查找速度的程序 各位帮帮忙.如何写一个能测试HashSet查找速度的程序(可通过不同的负载因子得到不同的的速度) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //: c11:MapPerformance.java// 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); }}基本就这样测试了,自己改改吧, Java RandomAccessFile 写入txt文件 大侠帮我改改代码 哪里有JBOSS的源代码下载 如何利用JSP程序显示服务端站点目录下的文件列表 装了JB2005 就是运行不了怎么办郁闷啊!! 有没有北京的朋友?对港湾公司了解吗? 如何把JBuilder7.0的一个工程内的JApplet移到另一个工程内 ,不损失UI上的东西 关于路径选择对话框 请问有谁知道怎么在JBUILDER里面加载*.OCX控件,很急!谢谢 关于jsdk1.3 ??? 关于抽象类的一个简单问题~~ 请写出下面代码的输出结果(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);
}
}
基本就这样测试了,自己改改吧,