Skip to content

Commit

Permalink
JDK 8 11 17 21 regexp perf
Browse files Browse the repository at this point in the history
  • Loading branch information
s50600822 committed Nov 8, 2023
1 parent 49fa753 commit 7d2650a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
29 changes: 29 additions & 0 deletions vs/java/regexp/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

### 8.332.08.1-amzn, java 11.0.16-amzn, java 17.0.8-amzn, java 21-graalce
```
sdk use java 8.332.08.1-amzn
javac Reg.java && java Reg
time: false [22197 ms]
sdk use java 11.0.16-amzn
javac Reg.java && java Reg
time: false [5 ms]
sdk use java 17.0.8-amzn
javac Reg.java && java Reg
time: false [2 ms]
sdk use java 21-graalce
javac Reg.java && java Reg
time: false [0 ms]
```

### ref
https://kean.blog/post/regex-matcher
https://kean.blog/post/regex-matcher
https://algs4.cs.princeton.edu/54regexp/
https://querix.com/go/lycia/Content/06_reference/4gl/regular_expressions/regex_algorithms.htm
https://sedgewick.io/wp-content/uploads/2022/04/Algs20-RegularExpressions.pdf
28 changes: 28 additions & 0 deletions vs/java/regexp/Reg.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Reg {

public static void main(String[] args) {
long startTime = System.nanoTime();
boolean m = reg();
long endTime = System.nanoTime();
long durationMs = (endTime - startTime)/1000000;

System.out.println(String.format("time: %s [%s ms]" , m ,durationMs));
}

public static String reverseString(String str) {
if (str.isEmpty())
return str;
return reverseString(str.substring(1)) + str.charAt(0);
}

public static boolean reg(){
final String expr = "(a|b|ab)*bc";
final String in = "ababababababababababababababababababababababababababababac";
Pattern p = Pattern.compile(expr);
Matcher m = p.matcher(in);
return m.matches();
}
}

0 comments on commit 7d2650a

Please sign in to comment.