Consider the following cases:
Case 1: (fewer comments in for loop )
import java.io.IOException; public class Stopwatch { private static long start; public static void main(String args[]) throws IOException { start = System.currentTimeMillis(); for (int i = 0; i < 1000000000; i++) { } System.out.println("The time taken to execute the code is: " + (System.currentTimeMillis() - start)/1000.0); } }
Code Lead Time: 2,259
Case 2: (More comments in the for loop )
import java.io.IOException; public class Stopwatch { private static long start; public static void main(String args[]) throws IOException { start = System.currentTimeMillis(); for (int i = 0; i < 1000000000; i++) { } System.out.println("The time taken to execute the code is: " + (System.currentTimeMillis() - start)/1000.0); } }
Code Lead Time: 2.279
Case 3: (No comments, empty for loop )
import java.io.IOException; public class Stopwatch { private static long start; public static void main(String args[]) throws IOException { start = System.currentTimeMillis(); for (int i = 0; i < 1000000000; i++) { } System.out.println("The time taken to execute the code is: " + (System.currentTimeMillis() - start)/1000.0); } }
Code Lead Time: 2.249
Configuration: JDK 1.5, 3rd Gen i5, 4GB Ram.
Question: If we add more comments, does the program require more time to execute? Why?
source share