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 01e57c9
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
50 changes: 50 additions & 0 deletions vs/java/regexp/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

### 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]
```

### 21 Amaz vs 21 Graal native (nanosec scale)

```
Using java version 21-amzn in this shell.
[2295042 ns]
[2043833 ns]
[2035208 ns]
[2039458 ns]
[2123292 ns]
[2206541 ns]
graalvm native
[115458 ns]
[140333 ns]
[101666 ns]
[122791 ns]
[116959 ns]
[177125 ns]
[119584 ns]
```

### 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 01e57c9

Please sign in to comment.