fork(170) download
  1. class A {
  2. public static void main(String[] args) {
  3. int n = 8000;
  4.  
  5. int g[][] = new int[n][n];
  6. long st, en;
  7.  
  8. // one
  9. st = System.nanoTime();
  10. for(int i = 0; i < n; i++) {
  11. for(int j = 0; j < n; j++) {
  12. g[i][j] = i + j;
  13. }
  14. }
  15. en = System.nanoTime();
  16. System.out.println("\nTwo time " + (en - st)/1000000.d + " msc");
  17.  
  18. // two
  19. st = System.nanoTime();
  20. for(int i = 0; i < n; i++) {
  21. g[i][i] = i + i;
  22. for(int j = 0; j < i; j++) {
  23. g[j][i] = g[i][j] = i + j;
  24. }
  25. }
  26. en = System.nanoTime();
  27. System.out.println("\nTwo time " + (en - st)/1000000.d + " msc");
  28. }
  29. }
Success #stdin #stdout 2.5s 380224KB
stdin
Standard input is empty
stdout
Two time 164.607335 msc

Two time 1833.918251 msc