Skip to content

Commit

Permalink
[core] Add writing different data for keys in lookup file store bench…
Browse files Browse the repository at this point in the history
…mark (#3890)
  • Loading branch information
FangYongs authored Aug 5, 2024
1 parent e0dfe45 commit 5d7041f
Showing 1 changed file with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,16 @@ public static List<Integer> getVarSeg() {
}

@TestTemplate
void testLookupWriter() {
writeLookupDataBenchmark(generateSequenceInputs(0, recordCount));
void testLookupWriterSameValue() {
writeLookupDataBenchmark(generateSequenceInputs(0, recordCount), true);
}

public void writeLookupDataBenchmark(byte[][] inputs) {
@TestTemplate
void testLookupWriterDiffValue() {
writeLookupDataBenchmark(generateSequenceInputs(0, recordCount), false);
}

private void writeLookupDataBenchmark(byte[][] inputs, boolean sameValue) {
Benchmark benchmark =
new Benchmark("writer-" + inputs.length, inputs.length)
.setNumWarmupIters(1)
Expand All @@ -84,7 +89,7 @@ public void writeLookupDataBenchmark(byte[][] inputs) {
5,
() -> {
try {
writeData(options, inputs, valueLength);
writeData(options, inputs, valueLength, sameValue);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -95,10 +100,12 @@ public void writeLookupDataBenchmark(byte[][] inputs) {
benchmark.run();
}

private void writeData(CoreOptions options, byte[][] inputs, int valueLength)
private void writeData(CoreOptions options, byte[][] inputs, int valueLength, boolean sameValue)
throws IOException {
byte[] value = new byte[valueLength];
Arrays.fill(value, (byte) 1);
byte[] value1 = new byte[valueLength];
byte[] value2 = new byte[valueLength];
Arrays.fill(value1, (byte) 1);
Arrays.fill(value2, (byte) 2);
LookupStoreFactory factory =
LookupStoreFactory.create(
options,
Expand All @@ -108,8 +115,16 @@ private void writeData(CoreOptions options, byte[][] inputs, int valueLength)

File file = new File(tempDir.toFile(), UUID.randomUUID().toString());
LookupStoreWriter writer = factory.createWriter(file, null);
boolean first = true;
for (byte[] input : inputs) {
writer.put(input, value);
if (first) {
writer.put(input, value1);
} else {
writer.put(input, value2);
}
if (!sameValue) {
first = !first;
}
}
writer.close();
}
Expand Down

0 comments on commit 5d7041f

Please sign in to comment.