Thank you for reading my post Is there any way to calculate the time that an statement take to execute? I want the time to be calculated in MIcrosecond not in millisecods. is there any way to do this ?
This is only feasible if the line that you want to time is going to take quite a while to execute. By quite a while, I guess I mean tens of milliseconds. For most single lines of code, you have no chance of getting an accurate timing, because they execute very fast and the timing is not that accurate; often the timing code would actually take longer to run than the single line you're trying to time!
Note that nanoTime() does not necessarily get you what you want. Sure, it has nanosecond precision, but that does not mean it has nanosecond accuracy. Consider a cheap digital stop-watch. It may well display the runner's time to hundredths of a second, but the inaccuracy of the watch, combined with the difficulty of pressing the buttons at exactly the right time, means that the accuracy will never be better than a few tenths of a second.
Perhaps one should ask what you wish to achieve by timing a single statement? [ February 27, 2006: Message edited by: Peter Chase ]
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.