如何计算Java函数完成所需的时间? [英] How can I count the time it takes a function to complete in Java?

查看:37
本文介绍了如何计算Java函数完成所需的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要测量在Java中完成一个功能所花费的时间.我该怎么办?

I need to measure the time it takes for a function to complete in Java. How can I do that?

我想测量功能的时间消耗,而不是整个程序的时间消耗.

I want to measure the function's time consumption, not that of the full program.

推荐答案

long start = System.nanoTime();    
methodToBeTimed();
long elapsedTime = System.nanoTime() - start;

这篇关于如何计算Java函数完成所需的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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