szabivan

(a*)*b on a^n

Sep 14th, 2014
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.69 KB | None | 0 0
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. public class Main {
  5.         public static void main(String[] args) {
  6.                 String regex = "(a*)*b";
  7.                 String haystack = "a";
  8.                 for( int i = 1;i < 30; i++ ){
  9.                 long start = System.nanoTime();
  10.                 Pattern pattern = Pattern.compile( regex );
  11.                 Matcher matcher = pattern.matcher( haystack );
  12.                 matcher.find();
  13.                 long end = System.nanoTime();
  14.                 System.out.println("On " + haystack + ", .find run in " + (end - start) + " nanoseconds.");
  15.                 haystack = haystack + "a";
  16.                 }
  17.         }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment