fork download
  1. class A {
  2. public static void main(String[] args) {
  3. int n = 10000;
  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. st = System.nanoTime();
  30. for (int i = 0; i < n; i++) {
  31. g[i][i] = i << 1;
  32. for (int j = i + 1; j < n; j++) {
  33. g[i][j] = i + j;
  34. }
  35. }
  36. for (int i = 1; i < n; i++) {
  37. System.arraycopy(g[i-1], 1, g[i], 0, i);
  38. }
  39. en = System.nanoTime();
  40. System.out.println("\nThree time " + (en - st) / 1000000.d + " msc");
  41. }
  42. }
Runtime error #stdin #stdout #stderr 0.64s 380160KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at A.main(Main.java:5)