fork(53) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class A {
  6. public static void main (String[] args) throws java.lang.Exception {
  7. int g[] = new int[100000], k, s = 0;
  8. long st, en;
  9. // one
  10. st = System.nanoTime();
  11. for(int i = 1; i < g.length; i++) {
  12. k = (int)(g.length * Math.random()); // not used this
  13. s += k;
  14. g[i] = 1;
  15. }
  16. en = System.nanoTime();
  17. System.out.println("One time " + (en - st)/1000000.d + " msc");
  18.  
  19. // two
  20. st = System.nanoTime();
  21. for(int i = 1; i < g.length; i++) {
  22. k = (int)(g.length * Math.random());
  23. s += k;
  24. g[k] = 1;
  25. }
  26. en = System.nanoTime();
  27. System.out.println("Two time " + (en - st)/1000000.d + " msc");
  28. }
  29. }
Success #stdin #stdout 0.12s 380544KB
stdin
Standard input is empty
stdout
One time 15.849579 msc
One time 9.344496 msc
Two time 8.836397 msc
Two time 8.673017 msc