Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# JMH 1.10.3 (released 40 days ago)
# VM version: JDK 1.7.0_80, VM 24.80-b11
...
Benchmark Mode Cnt Score Error Units
SplitTest.plain avgt 30 0,107 ± 0,001 us/op
SplitTest.quote avgt 30 0,393 ± 0,003 us/op
# JMH 1.10.3 (released 40 days ago)
# VM version: JDK 1.8.0_40, VM 25.40-b25
...
Benchmark Mode Cnt Score Error Units
SplitTest.plain avgt 30 0,108 ± 0,001 us/op
SplitTest.quote avgt 30 0,380 ± 0,004 us/op
# JMH 1.10.3 (released 40 days ago)
# VM version: JDK 1.9.0-ea, VM 1.9.0-ea-b72
...
Benchmark Mode Cnt Score Error Units
SplitTest.plain avgt 30 0,108 ± 0,001 us/op
SplitTest.quote avgt 30 0,375 ± 0,003 us/op
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.annotations.*;
@Warmup(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 10, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@Fork(3)
@State(Scope.Benchmark)
public class SplitTest {
String s = "aa?bb";
@Benchmark
public void quote(Blackhole bh) {
bh.consume(s.split(Pattern.quote("?")));
}
@Benchmark
public void plain(Blackhole bh) {
bh.consume(s.split("\\?"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment