fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. public class Main
  8. {
  9. public static void main(String[] args)
  10. {
  11. int steps = 10000;
  12.  
  13. long start = System.nanoTime();
  14. String result = "";
  15. for (int i=0;i<steps;i++)
  16. {
  17. result+="A";
  18. }
  19. long stop = System.nanoTime();
  20. long time = stop - start;
  21. System.out.printf("%-58s%15.8f\n","Czas wykonania (w sekundach):",(stop-start)*Math.pow(10,-9));
  22.  
  23. start = System.nanoTime();
  24. StringBuilder result2 = new StringBuilder("");
  25. for (int i=0;i<steps;i++)
  26. {
  27. result2.append("A");
  28. }
  29. stop = System.nanoTime();
  30. time = stop-start;
  31. System.out.printf("%-58s%15.8f\n","Czas wykonania (w sekundach):",(stop-start)*Math.pow(10,-9));
  32. }
  33. }
Success #stdin #stdout 0.15s 4386816KB
stdin
Standard input is empty
stdout
Czas wykonania (w sekundach):                                  0.09781368
Czas wykonania (w sekundach):                                  0.00020787