开发者

Java time to run code in ns

I am trying to find the time taken by the Java 开发者_如何学JAVAcode to run, I am creating some huge object and want to track the time to the precision of nano seconds, if I use regular time stamp it says the code compiled in 0 seconds. Thanks


    long start = System.nanoTime();

    System.out.println("Hello World!");

    long end = System.nanoTime();
    System.out.println(end - start);

The docs

edit
it says the code compiled in 0 seconds
So, do you want compilation time or running time?


You need to take a look at

System.nanoTime()

The docs do say that nanosecond accuracy cannot be guaranteed, but it will give you more accurate results than 0seconds.

http://download.oracle.com/javase/1.5.0/docs/api/java/lang/System.html#nanoTime()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜