Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Main {
- public static void main(String[] args) {
- String regex = "";
- String haystack = "";
- for( int i = 1; i < 30; i++ ){
- regex = "a?" + regex + "a";
- haystack = "a" + haystack;
- long start = System.nanoTime();
- Pattern pattern = Pattern.compile( regex );
- Matcher matcher = pattern.matcher( haystack );
- if( matcher.find() ){
- long end = System.nanoTime();
- System.err.println("i = " + i + " found in " + (end - start) + " nanoseconds.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment