Skip to content

Instantly share code, notes, and snippets.

@doom369
Created August 29, 2020 21:36
Show Gist options
  • Save doom369/5563e5ca5532c9714e90ae3e89c3630c to your computer and use it in GitHub Desktop.
Save doom369/5563e5ca5532c9714e90ae3e89c3630c to your computer and use it in GitHub Desktop.

Revisions

  1. doom369 created this gist Aug 29, 2020.
    18 changes: 18 additions & 0 deletions ReplaceAllPrecompiled.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    @BenchmarkMode(Mode.AverageTime)
    @Fork(1)
    @State(Scope.Thread)
    @Warmup(iterations = 5, time = 1)
    @OutputTimeUnit(TimeUnit.NANOSECONDS)
    @Measurement(iterations = 10, time = 1)
    public class ReplaceAllPrecompiled {

    @Param({"", "somePathNoDoT", "some.Path.With.Dot"})
    String value;
    private static final Pattern DOT_PATTERN = Pattern.compile("\\.");

    @Benchmark
    public String replaceAllWithPrecompiled() {
    return DOT_PATTERN.matcher(value).replaceAll("%2E");
    }

    }