Java 如果我要做一些测试,我已经有答案了。而不是创建新问题的参数。。。但是谢谢你的意见。对,第二种方法应该有更好的性能。我编辑了上面的答案。谢谢。对,第二种方法应该有更好的性能。我编辑了上面的答案。谢谢 HashMap<String, Location&g

Java 如果我要做一些测试,我已经有答案了。而不是创建新问题的参数。。。但是谢谢你的意见。对,第二种方法应该有更好的性能。我编辑了上面的答案。谢谢。对,第二种方法应该有更好的性能。我编辑了上面的答案。谢谢 HashMap<String, Location&g,java,Java,如果我要做一些测试,我已经有答案了。而不是创建新问题的参数。。。但是谢谢你的意见。对,第二种方法应该有更好的性能。我编辑了上面的答案。谢谢。对,第二种方法应该有更好的性能。我编辑了上面的答案。谢谢 HashMap<String, Location> one = new HashMap<String, Location> HashMap<String, Integer> two = new HashMap<String, Integer> Hash


如果我要做一些测试,我已经有答案了。而不是创建新问题的参数。。。但是谢谢你的意见。对,第二种方法应该有更好的性能。我编辑了上面的答案。谢谢。对,第二种方法应该有更好的性能。我编辑了上面的答案。谢谢
HashMap<String, Location> one = new HashMap<String, Location>
HashMap<String, Integer> two = new HashMap<String, Integer>
HashMap<String, NewClass> one = new HashMap<String, NewClass>
class NewClass {

    Location loc;
    Integer int;
}
// create 2 hashes with 1M entries
for (int i = 0; i < 1000000; i++){
    String s = new BigInteger(80, random).toString(32);
    hash1.put(s, s);
    hash2.put(s, new BigInteger(80, random).intValue());
}

// create 1 hash with 1M entries
for (int i = 0; i < 1000000; i++){
    String s = new BigInteger(80, random).toString(32);
    NewClass n = new NewClass();
    n.i = new BigInteger(80, random).intValue();
    n.loc = s;
    hash3.put(s, n);
}

// 5M lookups
long start = new Date().getTime();
for (int i = 0; i < 5000000; i++){
    String s = "AAA";
    hash1.get(s);
    hash2.get(s);
}
System.out.println("Approach 1 (2 hashes): " + (new Date().getTime() - start));

// 5M lookups
long start2 = new Date().getTime();
for (int i = 0; i < 5000000; i++){
    String s = "BBB";
    hash3.get(s);
}
System.out.println("Approach 2 (1 hash): " + (new Date().getTime() - start2));