Skip to content

Commit

Permalink
8292196: Reduce runtime of java.util.regex microbenchmarks
Browse files Browse the repository at this point in the history
Reviewed-by: rriggs
  • Loading branch information
Eric Caspole committed Aug 15, 2022
1 parent b00eede commit b5707b0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
6 changes: 3 additions & 3 deletions test/micro/org/openjdk/bench/java/util/regex/Exponential.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
*/
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Fork(1)
@Warmup(iterations = 1)
@Measurement(iterations = 4)
@Fork(2)
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@State(Scope.Benchmark)
public class Exponential {
/** Run length of non-matching consecutive whitespace chars. */
Expand Down
18 changes: 4 additions & 14 deletions test/micro/org/openjdk/bench/java/util/regex/PatternBench.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
Expand All @@ -39,6 +40,9 @@

@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Fork(2)
@Warmup(iterations = 4, time = 2, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 4, time = 2, timeUnit = TimeUnit.SECONDS)
@State(Scope.Thread)
public class PatternBench {

Expand Down Expand Up @@ -71,45 +75,33 @@ public void setup() {
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public long longStringGraphemeMatches() {
return graphemePattern.matcher(flagsString.repeat(3)).results().count();
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int splitFlags() {
return graphemeBoundaryPattern.split(flagsString).length;
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public boolean canonicalJmodMatch() {
return jmodCanonicalPattern.matcher(fileTestString).matches();
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public boolean normalJmodMatch() {
return jmodPattern.matcher(fileTestString).matches();
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public boolean charPatternMatch() {
return charPattern.matcher(charPatternStrings[0]).matches()
&& charPattern.matcher(charPatternStrings[1]).matches()
&& charPattern.matcher(charPatternStrings[2]).matches();
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public boolean charPatternMatchWithCompile() {
Pattern p = Pattern.compile(charPatternRegex);
return p.matcher(charPatternStrings[0]).matches()
Expand All @@ -118,8 +110,6 @@ public boolean charPatternMatchWithCompile() {
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public Pattern charPatternCompile() {
return Pattern.compile(charPatternRegex);
}
Expand Down
6 changes: 3 additions & 3 deletions test/micro/org/openjdk/bench/java/util/regex/Primality.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Fork(1)
@Warmup(iterations = 1)
@Measurement(iterations = 4)
@Warmup(iterations = 2, time = 3, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 4, time = 3, timeUnit = TimeUnit.SECONDS)
@State(Scope.Benchmark)
public class Primality {
/** Number to be primality tested. */
@Param({"16", "17", "256", "257", "4096", "4099"})
@Param({"16", "17", /* "256", "257", */ "4096", "4099"})
// "64", "67", "1024", "1031", "16384", "16411"})
int n;

Expand Down
6 changes: 3 additions & 3 deletions test/micro/org/openjdk/bench/java/util/regex/Trim.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@
*/
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Fork(1)
@Warmup(iterations = 1)
@Measurement(iterations = 4)
@Fork(2)
@Warmup(iterations = 5, time = 3, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 3, timeUnit = TimeUnit.SECONDS)
@State(Scope.Benchmark)
public class Trim {
/** Run length of non-matching consecutive whitespace chars. */
Expand Down

1 comment on commit b5707b0

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.