Apache Lucene open-source search software
Fix preview and forbidden API usage in benchmark
ChrisHegarty1845ecb08a42
diff --git a/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/VectorScorerFloat32Benchmark.java b/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/VectorScorerFloat32Benchmark.javaindex 5ad753e7fbf..4f8223f918f 100644--- a/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/VectorScorerFloat32Benchmark.java+++ b/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/VectorScorerFloat32Benchmark.java@@ -16,12 +16,10 @@*/package org.apache.lucene.benchmark.jmh;-import static java.lang.foreign.ValueLayout.JAVA_FLOAT_UNALIGNED;import static org.apache.lucene.index.VectorSimilarityFunction.DOT_PRODUCT;import java.io.IOException;-import java.lang.foreign.MemorySegment;-import java.lang.foreign.ValueLayout;+import java.nio.ByteBuffer;import java.nio.ByteOrder;import java.nio.file.Files;import java.nio.file.Path;@@ -94,9 +92,6 @@ public class VectorScorerFloat32Benchmark {UpdateableRandomVectorScorer defDotScorer;UpdateableRandomVectorScorer optDotScorer;- static final ValueLayout.OfFloat JAVA_FLOAT_LE =- ValueLayout.JAVA_FLOAT_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN);-@Setup(Level.Trial)public void setup() throws IOException {var random = ThreadLocalRandom.current();@@ -104,10 +99,9 @@ public class VectorScorerFloat32Benchmark {dir = new MMapDirectory(path);try (IndexOutput out = dir.createOutput("vector.data", IOContext.DEFAULT)) {var ba = new byte[size * Float.BYTES];- var seg = MemorySegment.ofArray(ba);+ var buf = ByteBuffer.wrap(ba).order(ByteOrder.LITTLE_ENDIAN).asFloatBuffer();for (int v = 0; v < numVectors; v++) {- var src = MemorySegment.ofArray(randomVector(size, random));- MemorySegment.copy(src, JAVA_FLOAT_UNALIGNED, 0L, seg, JAVA_FLOAT_LE, 0L, size);+ buf.put(0, randomVector(size, random));out.writeBytes(ba, 0, ba.length);}}diff --git a/lucene/benchmark-jmh/src/test/org/apache/lucene/benchmark/jmh/TestVectorScorerFloat32Benchmark.java b/lucene/benchmark-jmh/src/test/org/apache/lucene/benchmark/jmh/TestVectorScorerFloat32Benchmark.javaindex 9d6d9db6ce1..27ac9486aa2 100644--- a/lucene/benchmark-jmh/src/test/org/apache/lucene/benchmark/jmh/TestVectorScorerFloat32Benchmark.java+++ b/lucene/benchmark-jmh/src/test/org/apache/lucene/benchmark/jmh/TestVectorScorerFloat32Benchmark.java@@ -19,6 +19,7 @@ package org.apache.lucene.benchmark.jmh;import java.io.IOException;import java.util.Arrays;import org.apache.lucene.tests.util.LuceneTestCase;+import org.apache.lucene.util.ArrayUtil;import org.junit.After;import org.junit.Before;@@ -45,21 +46,21 @@ public class TestVectorScorerFloat32Benchmark extends LuceneTestCase {public void testDotProduct() throws IOException {Arrays.fill(bench.scores, 0.0f);bench.dotProductDefault();- var expectedScores = Arrays.copyOfRange(bench.scores, 0, bench.scores.length);+ var expectedScores = ArrayUtil.copyArray(bench.scores);Arrays.fill(bench.scores, 0.0f);bench.dotProductDefaultBulk();- var bulkScores = Arrays.copyOfRange(bench.scores, 0, bench.scores.length);+ var bulkScores = ArrayUtil.copyArray(bench.scores);assertArrayEquals(expectedScores, bulkScores, delta);Arrays.fill(bench.scores, 0.0f);bench.dotProductOptScorer();- var actualScores = Arrays.copyOfRange(bench.scores, 0, bench.scores.length);+ var actualScores = ArrayUtil.copyArray(bench.scores);assertArrayEquals(expectedScores, actualScores, delta);Arrays.fill(bench.scores, 0.0f);bench.dotProductOptBulkScore();- actualScores = Arrays.copyOfRange(bench.scores, 0, bench.scores.length);+ actualScores = ArrayUtil.copyArray(bench.scores);assertArrayEquals(expectedScores, actualScores, delta);}}