gpt4 book ai didi

java - 如何计时Java程序执行速度

转载 作者:IT老高 更新时间:2023-10-28 11:44:27 27 4
gpt4 key购买 nike

你如何为java程序的执行计时?我不确定我应该使用哪个类来执行此操作。

我正在寻找类似的东西:

// Some timer starts here
for (int i = 0; i < length; i++) {
// Do something
}
// End timer here

System.out.println("Total execution time: " + totalExecutionTime);

最佳答案

final long startTime = System.currentTimeMillis();
for (int i = 0; i < length; i++) {
// Do something
}
final long endTime = System.currentTimeMillis();

System.out.println("Total execution time: " + (endTime - startTime));

关于java - 如何计时Java程序执行速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2572868/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com