fork(3) 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.  
  10. // two
  11. st = System.nanoTime();
  12. for(int i = 1; i < g.length; i++) {
  13. k = (int)(g.length * Math.random());
  14. s += k;
  15. g[k] = 1;
  16. }
  17. en = System.nanoTime();
  18. System.out.println("\nTwo time " + (en - st)/1000000.d + " msc");
  19.  
  20. // one
  21. st = System.nanoTime();
  22. for(int i = 1; i < g.length; i++) {
  23. k = (int)(g.length * Math.random()); // not used this
  24. s += k;
  25. g[i] = 1;
  26. }
  27. en = System.nanoTime();
  28. System.out.println("\nOne time " + (en - st)/1000000.d + " msc");
  29. }
  30. }
Success #stdin #stdout 0.1s 380352KB
stdin
Standard input is empty
stdout
Two time 15.945171 msc

One time 9.004415 msc