java - 如何在纳秒范围内找到 java 数学库函数的确切执行时间?
问题描述
我只想找出像 Math.sqrt() 这样的 java 数学函数在纳秒范围内的确切执行时间。我已经使用 System.nanoTime() 来查找时间,但每次运行它给出不同的执行时间。
import java.util.concurrent.TimeUnit;
import java.lang.Math;
class TimeUtil
{
public static void main(String[] args) throws InterruptedException {
long startTime = System.nanoTime();
/* ... the code being measured starts ... */
Math.sqrt(5.625);
/* ... the code being measured ends ... */
long endTime = System.nanoTime();
// get difference of two nanoTime values
long timeElapsed = endTime - startTime;
System.out.println("Execution time in nanoseconds : " + timeElapsed);
System.out.println("Execution time in milliseconds : " +
timeElapsed / 1000000);
}
}
解决方案
推荐阅读
- winapi - 使用 MultiByteToWideChar 从多字节字符串转换的宽字符串打印并写入文件错误
- python - 无法从函数中导入 selenium webdriver
- ios - 如何使用本机反应在我的firestore上的文档上添加多个对象?
- python - 如何修复“ModuleNotFoundError:没有名为 'azure.storage'\r 的模块”
- javascript - 如何在javascript文件的折叠代码中显示结束标记
- javascript - 从 JavaScript 历史记录中删除最后一个条目
- javascript - 无头 JS 后台任务未在 React-Native 中运行
- api - 哪个 Sabre API 可以获取航班上预订的乘客数量?
- javascript - 运行良好,但突然显示错误。例外:一天内服务调用次数过多:urlfetch
- regex - 正则表达式捕获中间网址