-
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 c6daf63
Showing
8 changed files
with
2,527 additions
and
44 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
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
69 changes: 69 additions & 0 deletions
69
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,69 @@ | ||
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.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 { | ||
|
||
@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); | ||
} | ||
} |
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
Oops, something went wrong.