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. A = new int[length];
  10. st = System.nanoTime();
  11. for (int i = 0; i < length; i++)
  12. {
  13. A[i] = k;
  14. }
  15. en = System.nanoTime();
  16. System.out.println("\nOne time=" + (en - st) / 1000000.d + " msc");
  17.  
  18. int cache = 10000;
  19. A = new int[length];
  20. int[] temp = new int[cache];
  21. st = System.nanoTime();
  22. for (int N = 0; N < length; N+=cache) {
  23. for (int i = 0; i < cache; i++)
  24. {
  25. temp[i] = k;
  26. }
  27. System.arraycopy(temp, 0, A, N, temp.length);
  28. }
  29. en = System.nanoTime();
  30. System.out.println("\nTwo time=" + (en - st) / 1000000.d + " msc");
  31.  
  32. }
  33. }
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
One time=1.958895 msc

Two time=0.175011 msc