如何计算Java程序的执行速度 [英] How to time Java program execution speed

查看:1059
本文介绍了如何计算Java程序的执行速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何计算java程序的执行时间?我不确定我应该用什么课程来做这件事。

How do you time the execution of a java program? I'm not sure what class I should use to do this.

我有点像找东西:

// 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程序的执行速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆