Java计算两个程序运行时间的实例
作者:jingxian 时间:2022-01-30 14:49:06
一、获取系统当前时间
long startTime = System.currentTimeMillis(); //获取开始时间
doSomething(); //测试的代码段
long endTime = System.currentTimeMillis(); //获取结束时间
System.out.println("程序运行时间:" + (endTime - startTime) + "ms"); //输出程序运行时间
二、以纳秒为单位计算
// 第二种是以纳秒为单位计算的。
long startTime=System.nanoTime(); //获取开始时间
doSomeThing(); //测试的代码段
long endTime=System.nanoTime(); //获取结束时间
System.out.println("程序运行时间: "+(endTime-startTime)+"ns");
标签:java,计算,程序,运行时间
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
spring boot实现过滤器和拦截器demo
2023-08-24 07:15:01
Java中自动装箱、拆箱引起的耗时详解
2023-01-11 11:42:42
java中LinkedList使用迭代器优化移除批量元素原理
2021-12-05 11:26:07
![](https://img.aspxhome.com/file/2023/0/66180_0s.png)
Java 数据结构之删除链表中重复的结点
2023-11-28 15:36:22
![](https://img.aspxhome.com/file/2023/6/60346_0s.gif)
深入了解Spring中最常用的11个扩展点
2023-07-05 17:46:40
![](https://img.aspxhome.com/file/2023/1/57531_0s.png)
IDEA(jetbrain通用)使用教程图解
2023-04-15 04:05:49
![](https://img.aspxhome.com/file/2023/9/61389_0s.gif)
深入探索Java常量池
2022-12-28 00:55:53
![](https://img.aspxhome.com/file/2023/0/66470_0s.jpg)
C++实现无重复字符的最长子串
2023-11-02 22:49:00
Redis缓存策略超详细讲解
2023-11-08 06:20:10
![](https://img.aspxhome.com/file/2023/8/66078_0s.png)
java之CSV大批量数据入库的实现
2021-06-30 15:53:49
![](https://img.aspxhome.com/file/2023/0/66170_0s.png)
JavaFX实现UI美观效果代码实例
2021-08-27 21:02:15
![](https://img.aspxhome.com/file/2023/6/62206_0s.jpg)
C#编程自学之数据类型和变量一
2023-07-30 02:45:49
![](https://img.aspxhome.com/file/2023/6/67056_0s.jpg)
java实现单机版五子棋
2022-12-20 20:15:07
![](https://img.aspxhome.com/file/2023/9/63379_0s.jpg)
浅谈Synchronized和Lock的区别
2023-10-26 04:28:33
基于Java实现缓存Cache的深入分析
2023-08-15 20:53:59
聊一聊Java的JVM类加载机制
2023-11-08 03:58:37
![](https://img.aspxhome.com/file/2023/5/58755_0s.png)
关于idea更新到2020.2.3无法创建web项目原因 library is not specified
2022-11-24 10:13:28
![](https://img.aspxhome.com/file/2023/6/64006_0s.png)
彻底掌握C语言strcpy函数的用法
2023-07-03 07:21:18
![](https://img.aspxhome.com/file/2023/4/103104_0s.png)
VSCode 搭建 Arm 远程调试环境的步骤详解
2023-06-27 08:54:36
![](https://img.aspxhome.com/file/2023/8/104448_0s.png)
如何解决修改StaticText的字体
2023-05-25 08:40:14
![](https://img.aspxhome.com/file/2023/9/66699_0s.png)