mirror of https://github.com/apache/lucene.git
Separated encode and decode benchmarks - initial commit
This commit is contained in:
parent
1cb896a985
commit
0b59eb3ee8
|
@ -77,42 +77,89 @@ public class DocIdEncodingBenchmark {
|
|||
@Param({"Bit21With3StepsEncoder", "Bit21With2StepsEncoder", "Bit24Encoder", "Bit32Encoder"})
|
||||
String encoderName;
|
||||
|
||||
@Param({"encode", "decode"})
|
||||
String methodName;
|
||||
|
||||
private static final int INPUT_SCALE_FACTOR = 2_00_000;
|
||||
|
||||
private DocIdEncoder docIdEncoder;
|
||||
|
||||
private Path tmpDir;
|
||||
|
||||
private IndexInput in;
|
||||
|
||||
private IndexOutput out;
|
||||
|
||||
private final int[] scratch = new int[512];
|
||||
|
||||
@Setup(Level.Trial)
|
||||
public void init() throws IOException {
|
||||
tmpDir = Files.createTempDirectory("docIdJmh");
|
||||
docIdEncoder = DocIdEncoder.SingletonFactory.fromName(encoderName);
|
||||
// Create file once for decoders to read from in every iteration
|
||||
if (methodName.equalsIgnoreCase("decode")) {
|
||||
String dataFile =
|
||||
String.join("_", "docIdJmhData", docIdEncoder.getClass().getSimpleName(), "DecoderInput");
|
||||
try (Directory dir = new NIOFSDirectory(tmpDir)) {
|
||||
out = dir.createOutput(dataFile, IOContext.DEFAULT);
|
||||
encode();
|
||||
} finally {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@TearDown(Level.Trial)
|
||||
public void finish() throws IOException {
|
||||
if (methodName.equalsIgnoreCase("decode")) {
|
||||
String dataFile =
|
||||
String.join("_", "docIdJmhData", docIdEncoder.getClass().getSimpleName(), "DecoderInput");
|
||||
Files.delete(tmpDir.resolve(dataFile));
|
||||
}
|
||||
Files.delete(tmpDir);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void performEncodeDecode() throws IOException {
|
||||
public void executeEncodeOrDecode() throws IOException {
|
||||
String dataFile =
|
||||
String.join(
|
||||
"_",
|
||||
"docIdJmhData_",
|
||||
"docIdJmhData",
|
||||
docIdEncoder.getClass().getSimpleName(),
|
||||
String.valueOf(System.nanoTime()));
|
||||
if (methodName.equalsIgnoreCase("encode")) {
|
||||
try (Directory dir = new NIOFSDirectory(tmpDir)) {
|
||||
try (IndexOutput out = dir.createOutput(dataFile, IOContext.DEFAULT)) {
|
||||
out = dir.createOutput(dataFile, IOContext.DEFAULT);
|
||||
encode();
|
||||
} finally {
|
||||
Files.delete(tmpDir.resolve(dataFile));
|
||||
out.close();
|
||||
}
|
||||
} else if (methodName.equalsIgnoreCase("decode")) {
|
||||
String inputFile =
|
||||
String.join("_", "docIdJmhData", docIdEncoder.getClass().getSimpleName(), "DecoderInput");
|
||||
try (Directory dir = new NIOFSDirectory(tmpDir)) {
|
||||
in = dir.openInput(inputFile, IOContext.DEFAULT);
|
||||
decode();
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown method: " + methodName);
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void encode() throws IOException {
|
||||
for (int[] docIdSequence : docIdSequences) {
|
||||
for (int i = 1; i <= INPUT_SCALE_FACTOR; i++) {
|
||||
docIdEncoder.encode(out, 0, docIdSequence.length, docIdSequence);
|
||||
}
|
||||
}
|
||||
}
|
||||
try (IndexInput in = dir.openInput(dataFile, IOContext.DEFAULT)) {
|
||||
|
||||
@Benchmark
|
||||
public void decode() throws IOException {
|
||||
for (int[] docIdSequence : docIdSequences) {
|
||||
for (int i = 1; i <= INPUT_SCALE_FACTOR; i++) {
|
||||
docIdEncoder.decode(in, 0, docIdSequence.length, scratch);
|
||||
|
@ -128,10 +175,6 @@ public class DocIdEncodingBenchmark {
|
|||
// }
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
Files.delete(tmpDir.resolve(dataFile));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue