szabivan

Java (a?)^na^n

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