progs/catastrophic.java
changeset 474 4bdf0dedd708
parent 420 25bc57b32efa
child 558 447ed6c7cdad
equal deleted inserted replaced
473:dc528091eb70 474:4bdf0dedd708
     6 import java.util.regex.*;
     6 import java.util.regex.*;
     7 
     7 
     8 public class catastrophic {
     8 public class catastrophic {
     9     public static void main(String[] args) {
     9     public static void main(String[] args) {
    10 
    10 
    11         //we always run all the tests twice -> warmup of the JVM
    11         //we always run all the tests twice -> to warmup of the JVM
    12         for (int runs = 0; runs < 2; runs++) {
    12         for (int runs = 0; runs < 2; runs++) {
    13             
    13             
    14             Pattern pattern = Pattern.compile("(a*)*b");
    14             Pattern pattern = Pattern.compile("(a*)*b");
    15             
    15             
    16             // Run from 5 to 28 characters
    16             // Run from 5 to 28 characters
    23                 // Measure the average duration of two calls...  
    23                 // Measure the average duration of two calls...  
    24                 long start = System.nanoTime();
    24                 long start = System.nanoTime();
    25                 for (int i = 0; i < 2; i++) {
    25                 for (int i = 0; i < 2; i++) {
    26                     pattern.matcher(input).find();
    26                     pattern.matcher(input).find();
    27                 }
    27                 }
    28                 
    28 
       
    29                 // Print out time
    29                 System.out.println(length + " " + input + ": " 
    30                 System.out.println(length + " " + input + ": " 
    30                        + ((System.nanoTime() - start) / 2000000000d) 
    31                        + ((System.nanoTime() - start) / 2000000000d) 
    31                        + "s");
    32                        + "s");
    32             }
    33             }
    33         }
    34         }