Created
August 29, 2020 20:49
-
-
Save doom369/d3a2167df10585bbc6f87f28fe180e05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@BenchmarkMode(Mode.AverageTime) | |
@Fork(1) | |
@State(Scope.Thread) | |
@Warmup(iterations = 5, time = 1) | |
@OutputTimeUnit(TimeUnit.NANOSECONDS) | |
@Measurement(iterations = 10, time = 1) | |
public class ReplaceAll { | |
@Param({"", "somePathNoDoT", "some.Path.With.Dot"}) | |
String value; | |
@Benchmark | |
public String replaceAllWithContains() { | |
return value.contains(".") ? value.replaceAll("\\.", "%2E") : value; | |
} | |
@Benchmark | |
public String replaceAll() { | |
return value.replaceAll("\\.", "%2E"); | |
} | |
@Benchmark | |
public String replace() { | |
return value.replace(".", "%2E"); | |
} | |
@Benchmark | |
public String replaceWithContains() { | |
return value.contains(".") ? value.replace(".", "%2E") : value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment