-
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
5f27f95
commit 7dc27d2
Showing
2 changed files
with
67 additions
and
88 deletions.
There are no files selected for viewing
88 changes: 0 additions & 88 deletions
88
src/jmh/java/dev/blaauwendraad/masker/json/JsonMaskMultipleTargetKeysBenchmark.java
This file was deleted.
Oops, something went wrong.
67 changes: 67 additions & 0 deletions
67
src/jmh/java/dev/blaauwendraad/masker/json/JsonMaskerBenchmark.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,67 @@ | ||
package dev.blaauwendraad.masker.json; | ||
|
||
import dev.blaauwendraad.masker.json.config.JsonMaskerAlgorithmType; | ||
import dev.blaauwendraad.masker.json.config.JsonMaskingConfig; | ||
import org.openjdk.jmh.annotations.*; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.HashSet; | ||
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) | ||
public static class State { | ||
|
||
@Param({"200b", "4kb", "128kb", "2mb"}) | ||
String jsonSize; | ||
|
||
@Param({"1", "100"}) | ||
int numberOfKeys; | ||
|
||
@Param({"-1", "8"}) | ||
int obfuscationLength; | ||
private String jsonString; | ||
private byte[] jsonBytes; | ||
private JsonMasker jsonMasker; | ||
|
||
@Setup | ||
public synchronized void setup() { | ||
Set<String> keysToBeMasked = getTargetKeys(numberOfKeys); | ||
|
||
jsonString = ParseAndMaskUtil.readJsonFromFileAsString("json-%s.json".formatted(jsonSize), this.getClass()); | ||
jsonBytes = jsonString.getBytes(StandardCharsets.UTF_8); | ||
|
||
jsonMasker = JsonMasker.getMasker( | ||
JsonMaskingConfig.custom(keysToBeMasked, JsonMaskingConfig.TargetKeyMode.MASK) | ||
.obfuscationLength(obfuscationLength) | ||
.algorithmTypeOverride(JsonMaskerAlgorithmType.KEYS_CONTAIN) | ||
.build() | ||
); | ||
} | ||
|
||
private Set<String> getTargetKeys(int numberOfKeys) { | ||
Set<String> targetKeys = new HashSet<>(); | ||
for (int i = 0; i < numberOfKeys; i++) { | ||
targetKeys.add("someSecret" + i); | ||
} | ||
return targetKeys; | ||
} | ||
} | ||
|
||
@Benchmark | ||
public String maskJsonString(State state) { | ||
return state.jsonMasker.mask(state.jsonString); | ||
} | ||
|
||
@Benchmark | ||
public byte[] maskJsonBytes(State state) { | ||
return state.jsonMasker.mask(state.jsonBytes); | ||
} | ||
} |