fork(1) download
  1. class Test {
  2. public static void main(String[] args) {
  3.  
  4. int k = 10000;
  5. long st, en;
  6. int[] A;
  7. int length = 100000;
  8.  
  9. int cache = 10000;
  10. A = new int[length];
  11. int[] temp = new int[cache];
  12. st = System.nanoTime();
  13. for (int N = 0; N < length; N+=cache) {
  14. for (int i = 0; i < cache; i++) {
  15. temp[i] = k;
  16. }
  17. System.arraycopy(temp, 0, A, N, temp.length);
  18. }
  19. en = System.nanoTime();
  20. System.out.println("\nTwo time=" + (en - st) / 1000000.d + " msc");
  21. A = new int[length];
  22. st = System.nanoTime();
  23. for (int i = 0; i < length; i++)
  24. {
  25. A[i] = k;
  26. }
  27. en = System.nanoTime();
  28. System.out.println("\nOne time=" + (en - st) / 1000000.d + " msc");
  29.  
  30. }
  31. }
Success #stdin #stdout 0.11s 320576KB
stdin
Standard input is empty
stdout
Two time=2.039929 msc

One time=0.118295 msc