-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4d2417
commit e82b04a
Showing
3 changed files
with
135 additions
and
35 deletions.
There are no files selected for viewing
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
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
76 changes: 76 additions & 0 deletions
76
src/jmh/java/dev/blaauwendraad/masker/json/JsonMaskerBenchmark_no_streaming.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package dev.blaauwendraad.masker.json; | ||
|
||
import dev.blaauwendraad.masker.json.config.JsonMaskingConfig; | ||
import dev.blaauwendraad.masker.json.util.JsonPathTestUtils; | ||
import org.jspecify.annotations.NullUnmarked; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Param; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Set; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@Warmup(iterations = 1, time = 3) | ||
@Fork(value = 1) | ||
@Measurement(iterations = 1, time = 3) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
@BenchmarkMode(Mode.Throughput) | ||
public class JsonMaskerBenchmark_no_streaming { | ||
|
||
@org.openjdk.jmh.annotations.State(Scope.Thread) | ||
@NullUnmarked | ||
public static class State { | ||
@Param({ "1kb", "32kb", "1mb" }) | ||
String jsonSize; | ||
@Param({ "unicode" }) | ||
String characters; | ||
@Param({ "0.1" }) | ||
double maskedKeyProbability; | ||
@Param({ "false", "true" }) | ||
boolean jsonPath; | ||
|
||
private String jsonString; | ||
private byte[] jsonBytes; | ||
private JsonMasker jsonMasker; | ||
|
||
@Setup | ||
public synchronized void setup() { | ||
Set<String> targetKeys = BenchmarkUtils.getTargetKeys(20); | ||
jsonString = BenchmarkUtils.randomJson(targetKeys, jsonSize, characters, maskedKeyProbability); | ||
jsonBytes = jsonString.getBytes(StandardCharsets.UTF_8); | ||
|
||
JsonMaskingConfig.Builder builder = JsonMaskingConfig.builder(); | ||
if (jsonPath) { | ||
builder.maskJsonPaths(JsonPathTestUtils.transformToJsonPathKeys(targetKeys, jsonString)); | ||
} else { | ||
builder.maskKeys(targetKeys); | ||
} | ||
jsonMasker = JsonMasker.getMasker(builder.build()); | ||
} | ||
} | ||
|
||
@Benchmark | ||
public String jsonMaskerString(State state) { | ||
return state.jsonMasker.mask(state.jsonString); | ||
} | ||
|
||
@Benchmark | ||
public byte[] jsonMaskerBytes(State state) { | ||
return state.jsonMasker.mask(state.jsonBytes); | ||
} | ||
|
||
@Benchmark | ||
public void jsonMaskerByteArrayStreams(State state) { | ||
state.jsonMasker.mask(new ByteArrayInputStream(state.jsonBytes), new ByteArrayOutputStream()); | ||
} | ||
} |