Skip to content

Instantly share code, notes, and snippets.

@lennartkoopmann
Last active December 27, 2015 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lennartkoopmann/1fc4d669c1f320ea9925 to your computer and use it in GitHub Desktop.
Save lennartkoopmann/1fc4d669c1f320ea9925 to your computer and use it in GitHub Desktop.
@State(Scope.Benchmark)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public class DateRegexBenchmark {
private static final String MESSAGE = "2015-12-15T07:36:25+00:00 sundaysister kernel[0]: **** [IOBluetoothHostControllerUSBTransport][ClearFeatureInterruptEndpointHalt] -- successfully posting another read for the mInt0InterruptPipe -- mInterruptPipeInOutstandingIOCount = 1 -- this = 0xb800";
private static Pattern VERY_DESCRIPTIVE;
private static Pattern DESCRIPTIVE;
private static Pattern OPEN;
@Setup
public void prepare() {
VERY_DESCRIPTIVE = Pattern.compile("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\+\\d{2}:\\d{2}");
DESCRIPTIVE = Pattern.compile(".{4}-.{2}-.{2}T.{2}:.{2}:.{2}\\+.{2}:.{2}");
OPEN = Pattern.compile(".*-.*-.*T.*:.*:.*\\+");
}
@Benchmark
public void veryDescriptiveMatch(Blackhole bh) {
bh.consume(VERY_DESCRIPTIVE.matcher(MESSAGE).matches());
}
@Benchmark
public void descriptiveMatch(Blackhole bh) {
bh.consume(DESCRIPTIVE.matcher(MESSAGE).matches());
}
@Benchmark
public void openMatch(Blackhole bh) {
bh.consume(OPEN.matcher(MESSAGE).matches());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment