Skip to content

Instantly share code, notes, and snippets.

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/1419e7887ba40161a38c to your computer and use it in GitHub Desktop.
Save lennartkoopmann/1419e7887ba40161a38c 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() {
VERY_DESCRIPTIVE.matcher(MESSAGE).matches();
}
@Benchmark
public void descriptiveMatch() {
DESCRIPTIVE.matcher(MESSAGE).matches();
}
@Benchmark
public void openMatch() {
OPEN.matcher(MESSAGE).matches();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment