【问题标题】:How to calculate the Performance/timetaken of a HashSet Search如何计算 HashSet 搜索的性能/耗时
【发布时间】:2018-06-21 05:00:51
【问题描述】:

我有一个 HashSet (a hashmap of (string and list of (hashmap of (two strings))))

HashSet<HashMap<String1,List<HashMap<String2,HashMap<String3,String4>>>>>

现在,我使用字符串输入(StrA 和 StrB)进行搜索,这应该在

上搜索 HashSet
  • StrA-->String1
  • StrB-->String2

它应该返回String 3和String 4的hashMap。

这是我的代码

HashMap<String, String> mapFound;

for (HashMap<String, List<HashMap<String, HashMap<String, String>>>> map : fooSet) {
if (map.containsKey(string1)) {
    List<HashMap<String, HashMap<String, String>>> list = map.get(string1);
    for(HashMap<String, HashMap<String, String>> map2 : list){
        if(map2.containsKey(string2)){
            mapFound = map2.get(string2);
        }
    }
}

}

我有多组哈希图;有的在开始,有的在最后。有些 Hashmap 的键值对很少,有些则更多。

现在,我如何衡量搜索和结果检索所用的时间?

【问题讨论】:

标签: java performance hashmap hashset


【解决方案1】:

循环前:

Long start = System.currentTimeMillis();

循环后:

System.out.println(System.currentTimeMillis() - start);

当然,它每次都会给你不同的结果。那是因为你的处理器同时做一些其他的事情。但是你可以启动它大约 50-100 次并获得平均值,这样更准确。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多