1
我正在嘗試測量115項收集的已用時間。 我的問題是,只有當我正在調試並通過使用StopWatch.stop();
時,我才能測量經過的時間當我運行我的測試正常值StopWatch.stop
是0
,雖然它是一個長期值。首先,我認爲我的收藏很小,但這個時間應該作爲長期價值傳遞。從標準庫使用StopWatch收集測試
// times-collection will be initialised somewhere else
//---------------------------------------------------------------
for (int i=0; i<10; i++){
final StopWatch stopwatchA = new StopWatch();
final StopWatch stopwatchB = new StopWatch();
Iterator<String> iterator = times.iterator();
stopwatchA.start();
while(iterator.hasNext()){
if (iterator.next().equals("XXX")) {
break;
}
}
stopwatchA.stop();
stopwatchB.start();
for (String tzd : times) {
if (tzd.equals("XXX")) {
break;
}
}
stopwatchB.stop();
if(stopwatchA.getTime() < stopwatchB.getTime()){
System.out.println("ITERATOR IS FASTER: iterator: " + estimatedTimeIterator + " FOR-TIME: " + estimatedTimeFor);
}else if(stopwatchA.getTime() > stopwatchB.getTime()){
System.out.println("FOR IS FASTER: iterator: " + estimatedTimeIterator + " FOR-TIME: " + estimatedTimeFor);
}
}
您正在使用哪個StopWatch?它是春天嗎? – developer
您可以使用我使用nanotime編寫的這個「計時碼錶」:https://github.com/marcolopes/dma/blob/master/org.dma.java/src/org/dma/java/util/Chronograph.java – marcolopes