Skip to content

Commit

Permalink
Committed wrong file :)
Browse files Browse the repository at this point in the history
  • Loading branch information
gavlyukovskiy authored and Breus committed Nov 20, 2023
1 parent 5f27f95 commit 7dc27d2
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 88 deletions.

This file was deleted.

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);
}
}

0 comments on commit 7dc27d2

Please sign in to comment.