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. public static void main (String[] args) throws java.lang.Exception {
  11. double radius = 100;
  12. double radiusSq = 10000;
  13.  
  14. startTime();
  15. for(int i=0; i<1000000; i++) {
  16. if(Math.sqrt(i) <= radiusSq) {
  17. String asd = "Just something to do";
  18. }
  19. }
  20. endTime();
  21.  
  22. startTime();
  23. for(int i=0; i<1000000; i++) {
  24. if(i <= radius) {
  25. String asd = "Just something to do";
  26. }
  27. }
  28. endTime();
  29. }
  30.  
  31. private static long time;
  32.  
  33. private static void startTime () {
  34. time = System.nanoTime();
  35. }
  36.  
  37. private static void endTime () {
  38. long c = System.nanoTime()-time;
  39. System.out.println(c+"ns ("+(c/1000000)+"ms)");
  40. }
  41. }
Success #stdin #stdout 0.12s 320256KB
stdin
Standard input is empty
stdout
15292354ns (15ms)
2070188ns (2ms)