From b833e731dc3c36e502d559ec9fb6607afb648662 Mon Sep 17 00:00:00 2001 From: expani Date: Wed, 7 Aug 2024 01:37:16 +0530 Subject: [PATCH] Avoid write/read to files per unique sequence --- .../lucene/benchmark/jmh/DocIdEncodingBenchmark.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/DocIdEncodingBenchmark.java b/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/DocIdEncodingBenchmark.java index 701f387eea3..d24fecb4f84 100644 --- a/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/DocIdEncodingBenchmark.java +++ b/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/DocIdEncodingBenchmark.java @@ -101,14 +101,16 @@ public class DocIdEncodingBenchmark { "docIdJmhData_", docIdEncoder.getClass().getSimpleName(), String.valueOf(System.nanoTime())); - for (int[] docIdSequence : docIdSequences) { - try (Directory dir = new NIOFSDirectory(tmpDir)) { - try (IndexOutput out = dir.createOutput(dataFile, IOContext.DEFAULT)) { + try (Directory dir = new NIOFSDirectory(tmpDir)) { + try (IndexOutput out = dir.createOutput(dataFile, IOContext.DEFAULT)) { + 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)) { + } + try (IndexInput in = dir.openInput(dataFile, IOContext.DEFAULT)) { + for (int[] docIdSequence : docIdSequences) { for (int i = 1; i <= INPUT_SCALE_FACTOR; i++) { docIdEncoder.decode(in, 0, docIdSequence.length, scratch); }