The time complexity of the code is known. The system on which the program was executed is Intel Corei3 which is dual core and CPU @ 2.4ghz — it has 4 logical processors. With these details, how can the execution time of the code be calculated?
public class PerfmTest {
public static void main(String[] args) {
getexeTime(1000000);
}
public static void getTime (long n) {
// long startTime = System.currentTimeMillis();
long startTime = System.nanoTime();
long k = 0;
for (int i = 1; i <=5; i++) {
// k = k + 5;
}
// long endTime = System.currentTimeMillis();
long estimatedTime = System.nanoTime() - startTime;
//System.out.println("Execution time for n = " + n + " is " + (endTime - startTime) + " milliseconds");
System.out.println("Execution time for n = " + n + " is " + estimatedTime + " nanoseconds");
}
}
The output was 855 nanoseconds.