Skip to content

Instantly share code, notes, and snippets.

@soldierkam
Last active January 25, 2016 21:43
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 soldierkam/c80e433aa9fbec35df5a to your computer and use it in GitHub Desktop.
Save soldierkam/c80e433aa9fbec35df5a to your computer and use it in GitHub Desktop.
AntPathMatcher benchmark
package org.sample;
import org.openjdk.jmh.annotations.*;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.openjdk.jmh.annotations.CompilerControl.Mode.DONT_INLINE;
import static org.openjdk.jmh.annotations.Scope.Benchmark;
import org.openjdk.jmh.infra.Blackhole;
import org.springframework.util.AntPathMatcher;
@State(Benchmark)
@Fork(1)
@Warmup(iterations = 15, time = 1, timeUnit = SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = SECONDS)
public class MyBenchmark {
private final AntPathMatcher matcher = new AntPathMatcher();
@Benchmark
public void isNotMatching(Blackhole bh) {
bh.consume(run("/my/path/**", "/somethink/completly/different"));
bh.consume(run("/my/path2/**", "/somethink2/completly/different"));
bh.consume(run("/my/path3/**", "/somethink3/completly/different"));
bh.consume(run("/path4/**", "/somethink3/completly/different"));
}
@Benchmark
public void isMatching(Blackhole bh) {
bh.consume(run("/my/path/**", "/my/path/is/very/long"));
bh.consume(run("/my/path2/**", "/my/path2/is/very/long/and/evenlonger"));
bh.consume(run("/path/**/long", "/path/is/very/long"));
bh.consume(run("/path2/**/longer", "/path2/is/very/long/and/longer"));
}
@Benchmark
public void suffix(Blackhole bh) {
bh.consume(run("/**/favico.ico", "/my/path/is/very/long"));
bh.consume(run("/**/favico.ico", "/my/path2/is/very/long"));
bh.consume(run("/**/favico.ico", "/my/path3/is/very/long"));
bh.consume(run("/**/favico", "/my/path3/favico"));
}
@CompilerControl(DONT_INLINE)
private boolean run(String pattern, String path) {
return matcher.match(pattern, path);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment