@@ -0,0 +1,1237 @@
+import java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;%0Aimport java.lang.NumberFormatException;%0A%0Aclass ExceptionCost %7B%0A  private static final String STR = %22abc%22;%0A  private static final String REGEX = %22%5C%5CA%5B-%5D?%5B0-9%5D+%5C%5Cz%22;%0A  private static final Pattern PATTERN = Pattern.compile(REGEX);%0A  public static void main(String args%5B%5D) throws Exception %7B%0A%0A    if (args.length %3C 2) %7B%0A      System.err.println(%22usage : java ExceptionCost %5Btype: plus or buffer%5D %5Bcount%5D%22);%0A      System.exit(1);%0A    %7D%0A    int count = Integer.parseInt(args%5B1%5D);%0A%0A    long before = System.currentTimeMillis();%0A    if (%22ex%22.equals(args%5B0%5D)) %7B%0A%0A      for (int i = 0; i %3C count; i++) %7B%0A        isNumberParse(STR);%0A      %7D%0A%0A    %7D else if (%22regex%22.equals(args%5B0%5D)) %7B%0A%0A      for (int i = 0; i %3C count; i++) %7B%0A        isNumberRegex(STR);%0A      %7D%0A    %7D%0A %0A    System.out.println(String.format(%22%25d ms%22, System.currentTimeMillis() - before));%0A    System.exit(0);%0A  %7D%0A%0A  private static boolean isNumberParse(String val) %7B%0A    try %7B%0A      Integer.parseInt(val);%0A      return true;%0A    %7D catch (NumberFormatException nfex) %7B%0A      return false;%0A    %7D%0A  %7D%0A%0A  private static boolean isNumberRegex(String val) %7B%0A    Matcher m1 = PATTERN.matcher(val);%0A    return m1.find();%0A  %7D%0A%7D

Add Exception Cost java