當嘗試使用System.nanoTime()
調查各種任務的運行時時,當輸入數據集足夠大時,該值變爲負值。System.nanoTime()變爲負
使用的示例代碼:
long start = System.nanoTime();
run();
long stop = System.nanoTime();
int diff = (int) (stop-start);
System.out.println(data_size+", "+diff);
的輸出,在一個越來越大的數據集調用run()
時,看起來是這樣的:
1, 80000
10, 4310000
50, 48077000
100, 171363000
250, 1061924000
500, 14018704
750, 998074408
1000, -41025184
1500, -81710664
2000, -273795736
2500, 768997600
3000, -39161248
這是否有道理的人?
可能的重複[爲什麼我使用System.nanoTime得到負的消逝時間()?](http://stackoverflow.com/questions/7866206/why-i-get-a-negative-elapsed-time-using-system-nanotime) – turbo
@turbo這不是重複的問題;這是由於轉換爲「int」的差異造成的。 – rgettman