我正在尝试编写一个代码,该代码以纳秒为单位计算 Java Map 的 containsKey 操作(例如它运行该操作的速度)。方法有一个Map<Double, Double> D作为参数,返回的值应该是 containsKey 操作的正常使用时间,单位为纳秒。我真的不知道如何继续这个。Netbeans IDE 给出错误消息,表示我在这里有某种无限循环。
到目前为止,这是我的代码:
import java.util.*;
public class calculateNanotime implements calculateNanotime{
/*
* Measures Map's containsKey -operaation's time frequency as nanoseconds.
* @param D Map to be tested
* @return containsKey -operation's duration as nanoseconds
*/
//@Override
public long containsKeyTime(Map<Double, Double> D) {
// I should try with different key values
D.containsKey(1.0);
long beginning = System.nanoTime();
long end = System.nanoTime();
long result = end - beginning;
//I have a code in another class of this package, which will be testing how well this code work, after this is ready
result = testable.containsKeyTime(D);
return result;
}
}
以下是错误消息:calculateNanotime.calculateNanotime.containsKeyTime(calculateNanotime.java:35) 线程“主”java.lang.StackOverflowError 中的异常
在calculateNanotime.calculateNanotime.containsKeyTime(calculateNanotime.java:42)