如何知道我程序运行了多少毫秒?程序占用多少内存

555555555555555 2009-03-03 07:30:31
用的是什么方法?java documents如何来查找这些命令?
...全文
261 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
boerruan 2009-03-05
  • 打赏
  • 举报
回复
C# 如何知道程序运行了多少毫秒?程序占用多少内存?
LoveJava520 2009-03-04
  • 打赏
  • 举报
回复
Long startTime = System.currentTimeMillis();
...... // 代码段
Long endTime = Sytem.currentTimeMillis();
System.out.println("Totle time is"+ (endTime-startTime)+"milliseconds");
nodisk 2009-03-04
  • 打赏
  • 举报
回复
Long startTime = System.currentTimeMillis();
//代码段
Long endTime = System.currentTimeMillis();
System.out.println("总计用时 "+(endTime-startTime)+"毫秒");

System.out.println("当前内存: "+Runtime.getRuntime().totalMemory());
System.out.println("当前空闲内存: "+Runtime.getRuntime().freeMemory());
System.out.println("最大内存: "+Runtime.getRuntime().maxMemory());

照着上面敲了一遍,加强记忆
LoveJava520 2009-03-04
  • 打赏
  • 举报
回复
Long startTime = System.currentTimeMillis();
...... // 代码段
Long endTime = Sytem.currentTimeMillis();
System.out.println("Totle time is"+ (endTime-startTime)+"milliseconds");
tristan0602 2009-03-04
  • 打赏
  • 举报
回复
来学习
rumlee 2009-03-04
  • 打赏
  • 举报
回复

long startTime = System.currentTimeMillis();
// TODO: 执行用户操作
long endTime = System.currentTimeMillis();
System.out.println("总计用时 "+ (endTime-startTime)+" 毫秒");

System.out.println("当前总内存:" + Runtime.getRuntime().totalMemory());
System.out.println("当前空闲内存:" + Runtime.getRuntime().freeMemory());
System.out.println("最大内存:" + Runtime.getRuntime().maxMemory());
Coolfatman 2009-03-04
  • 打赏
  • 举报
回复
其实在unix下比较简单 用time命令就行了。
lovewinner 2009-03-04
  • 打赏
  • 举报
回复
3q 楼主 咔咔
shenhuafan 2009-03-04
  • 打赏
  • 举报
回复
顶顶顶顶顶
wanchangjiu123 2009-03-04
  • 打赏
  • 举报
回复
来迟一步
11楼的说的好!!
发表于:2009-03-04 12:48:4511楼
Long startTime = System.currentTimeMillis();
//代码段
Long endTime = System.currentTimeMillis();
System.out.println("总计用时 "+(endTime-startTime)+"毫秒");

System.out.println("当前内存: "+Runtime.getRuntime().totalMemory());
System.out.println("当前空闲内存: "+Runtime.getRuntime().freeMemory());
System.out.println("最大内存: "+Runtime.getRuntime().maxMemory());

照着上面敲了一遍,加强记忆
starscc 2009-03-04
  • 打赏
  • 举报
回复
java.lang.System这个类有相关函数...
yefeng177 2009-03-04
  • 打赏
  • 举报
回复
jconsole
如果你的jvm是1.6, 那么任何运行参数都不要加, 运行程序前先暂停(比如说等待输入确认再执行), 开启jconsole, 选中你的程序, 可以图形化追踪内存使用, 线程, 等等.
supersunyi 2009-03-04
  • 打赏
  • 举报
回复
System.out.println("当前总内存:" + Runtime.getRuntime().totalMemory());
System.out.println("当前空闲内存:" + Runtime.getRuntime().freeMemory());
System.out.println("最大内存:" + Runtime.getRuntime().maxMemory());
以上使用的都是虚拟机的内存,并不是机器内存
supersunyi 2009-03-04
  • 打赏
  • 举报
回复
java的毫秒非常不好,如果要精确度高,那么用纳秒,我查过资料,java的毫秒误差一般16ms左右
用System.nanoTime()(jdk5以上支持)
传奇 2009-03-03
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 cnhuai 的回复:]
Long startTime = System.currentTimeMillis();
...... // 代码段
Long endTime = Sytem.currentTimeMillis();
System.out.println("Totle time is"+ (endTime-startTime)+"milliseconds");
[/Quote]
顶,这个是毫秒的哈.
热烈的红颜 2009-03-03
  • 打赏
  • 举报
回复
Long startTime = System.currentTimeMillis();
...... // 代码段
Long endTime = Sytem.currentTimeMillis();
System.out.println("Totle time is"+ (endTime-startTime)+"milliseconds");



占用内存 不清楚
cnhuai 2009-03-03
  • 打赏
  • 举报
回复
Long startTime = System.currentTimeMillis();
...... // 代码段
Long endTime = Sytem.currentTimeMillis();
System.out.println("Totle time is"+ (endTime-startTime)+"milliseconds");
eason521 2009-03-03
  • 打赏
  • 举报
回复
额,我也想知道

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧