fork download
  1. import java.util.*;
  2. import java.lang.*;
  3.  
  4. class Main
  5. {
  6. private static void test (String regex, String replace, int repetitions)
  7. {
  8. long startTime = System.currentTimeMillis();
  9. for (int i = 0; i < repetitions; i++)
  10. {
  11. String str = "30-Nov-2012 United Kingdom, 31-Oct-2012 31-Oct-2012 United Arab Emirates, 29-Oct-2012 31-Oct-2012 India, ";
  12. str.replaceAll(regex, replace);
  13. }
  14. long endTime = System.currentTimeMillis();
  15. System.out.println("Execution time: " + Long.toString(endTime - startTime));
  16. }
  17.  
  18. public static void main (String[] args) throws java.lang.Exception
  19. {
  20. test("(\\d{4})\\s", "$1@", 10000);
  21. test("(?<=\\d{4})\\s", "@", 10000);
  22. test("(\\d{4})\\s", "$1@", 10000);
  23. test("(?<=\\d{4})\\s", "@", 10000);
  24. test("(\\d{4})\\s", "$1@", 10000);
  25. test("(?<=\\d{4})\\s", "@", 10000);
  26. test("(\\d{4})\\s", "$1@", 10000);
  27. test("(?<=\\d{4})\\s", "@", 10000);
  28. }
  29. }
Success #stdin #stdout 1.01s 246080KB
stdin
Standard input is empty
stdout
Execution time: 164
Execution time: 140
Execution time: 96
Execution time: 135
Execution time: 95
Execution time: 133
Execution time: 94
Execution time: 130