java中测试for循环时间,如何测量for循环的执行时间?

I want to measure the execution time of for loops on various platforms like php, c, python, Java, javascript... How can i measure it?

I know these platforms so i am talking about these:

for (i = 0; i < 1000000; i++)

{

}

I don't want to measure anything within the loop.

Little bit modification:

@all Some of the friends of mine are saying compiler will optimize this code making this loop a useless loop. I agree with this. we can add a small statement like some incremental statement, but the fact is I just want to calculate the execution time of per iteration in a loop in various languages. By adding a incremental statement will add up the execution time and that will effect the results, cause on various platforms, execution time for incrementing a value also differ and that will make a result useless.

In short, in better way I should ask:

I WANT TO CALCULATE THE EXECUTION TIME OF PER ITERATION IN A LOOP on Various PLATFORMS..HOW CAN DO THIS???

edit---

I came to know about Python Profilers

Profiler modules ...which evaluate cpu time... absolute time.. Any suggestions???Meanwhile i am working on this...

解决方案

Note that it also depends on what exactly you want to achieve: do you care about the time your program waits due to it being preempted by the system scheduler? All the solutions above take actual time elapsed into consideration, but that also involves the time when other processes run instead of your own.

If you don't care about this, all of the solutions above are good. If you do care, you probably need some profiling software to actually see how long the loop takes.

I'd start with a program that does nothing but your loop and (in a linux environment at least) do time you-prg-executable.

Then I'd investigate if there are tools which work like time. Not sure, but I'd look at JRat for java, and gcc's gcov for C and C++. No doubt there are similar tools for the other languages. But, of course, you need to see if they give actual time or not.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值