Hi,
I just wanted to calculate the time taken to execute a piece of code.So i guess System.nanoTime() would work.

Thanks for all of you.

You are going to be bitten by the JIT compiler if you don't pay any attention; at first a piece of code is interpreted until the HotSpot mechanism hits: then it is going to be compiled and real machine code is running. Allow your code to 'warm up' and only then set your timers; if you want to time, say, a method P(), do this: