fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10.  
  11. public static void main(String[] args) {
  12. long startTime = System.nanoTime(); // Record the start time
  13.  
  14. // Perform 10,000,000 loops
  15. for (int i = 0; i < 10_000_000; i++) {
  16. // Just looping, no operation
  17. }
  18.  
  19. long endTime = System.nanoTime(); // Record the end time
  20. double durationInSeconds = (endTime - startTime) / 1_000_000_000.0; // Convert to seconds
  21.  
  22. System.out.printf("Time taken: %.3f seconds%n", durationInSeconds);
  23. }
  24. }
Success #stdin #stdout 0.09s 54124KB
stdin
Standard input is empty
stdout
Time taken: 0.002 seconds