8292196: Reduce runtime of java.util.regex microbenchmarks

Reviewed-by: rriggs
This commit is contained in:
Eric Caspole 2022-08-15 16:54:39 +00:00
parent b00eedeb02
commit b5707b0376
4 changed files with 13 additions and 23 deletions

View File

@ -44,9 +44,9 @@ import java.util.regex.Pattern;
*/
@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. */

View File

@ -24,6 +24,7 @@ package org.openjdk.bench.java.util.regex;
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;
@ -39,6 +40,9 @@ import java.util.regex.PatternSyntaxException;
@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 {
@ -71,36 +75,26 @@ public class PatternBench {
}
@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()
@ -108,8 +102,6 @@ public class PatternBench {
}
@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public boolean charPatternMatchWithCompile() {
Pattern p = Pattern.compile(charPatternRegex);
return p.matcher(charPatternStrings[0]).matches()
@ -118,8 +110,6 @@ public class PatternBench {
}
@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public Pattern charPatternCompile() {
return Pattern.compile(charPatternRegex);
}

View File

@ -45,12 +45,12 @@ import java.util.regex.Pattern;
@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;

View File

@ -75,9 +75,9 @@ import java.util.regex.Pattern;
*/
@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. */