Question about System.nanoTime()?
I'm working a problem that I need to calculate runtime complexity of a particular function. However, I have some troubles understand how Java's API "nanoTime()" works. When I tried this example, each time I run it, I got different result. I think it should be the same every time, but it was not. Can anyone help me explain how this function works? and how to calculate runtime of a particular function?
public static void main( String args )
long beg = System.nanoTime();
for( int i = 0; i < 10000; ++i )
if( i == 1 )
System.out.print( "\n" );
long end = System.nanoTime();
System.out.println( end - beg );