System.out.printf("普通循环费时: %d%n", endTime - startTime);优化
时间: 2023-07-15 17:14:29 浏览: 54
可以使用`System.nanoTime()`来获取更高精度的时间戳,代码如下所示:
```
long startTime = System.nanoTime();
// 待优化的代码块
long endTime = System.nanoTime();
System.out.printf("优化后的循环费时: %d ns%n", endTime - startTime);
```
这样能够更准确地衡量代码块的执行时间。另外,建议对待优化的代码块进行具体分析,找到瓶颈所在,再进行优化,以达到更好的效果。
相关推荐
![.zip](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![ppt](https://img-home.csdnimg.cn/images/20210720083527.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)