uschindler commented on code in PR #13339: URL: https://github.com/apache/lucene/pull/13339#discussion_r1589486399
########## lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/VectorScorerBenchmark.java: ########## @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.lucene.benchmark.jmh; + +import static org.apache.lucene.index.VectorSimilarityFunction.DOT_PRODUCT; + +import java.io.IOException; +import java.nio.file.Files; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.TimeUnit; +import org.apache.lucene.codecs.lucene95.OffHeapByteVectorValues; +import org.apache.lucene.internal.vectorization.VectorizationProvider; +import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; +import org.apache.lucene.store.IndexInput; +import org.apache.lucene.store.IndexOutput; +import org.apache.lucene.store.MMapDirectory; +import org.apache.lucene.util.IOUtils; +import org.apache.lucene.util.hnsw.RandomAccessVectorValues; +import org.apache.lucene.util.hnsw.RandomVectorScorerSupplier; +import org.openjdk.jmh.annotations.*; + +@BenchmarkMode(Mode.Throughput) +@OutputTimeUnit(TimeUnit.MICROSECONDS) +@State(Scope.Benchmark) +// first iteration is complete garbage, so make sure we really warmup +@Warmup(iterations = 4, time = 1) +// real iterations. not useful to spend tons of time here, better to fork more +@Measurement(iterations = 5, time = 1) +// engage some noise reduction +@Fork( + value = 3, + jvmArgsAppend = {"-Xmx2g", "-Xms2g", "-XX:+AlwaysPreTouch"}) +public class VectorScorerBenchmark { + + @Param({"1", "128", "207", "256", "300", "512", "702", "1024"}) + int size; + + Directory dir; + IndexInput in; + RandomAccessVectorValues vectorValues; + byte[] vec1, vec2; + RandomVectorScorerSupplier scorer; + + @Setup(Level.Iteration) + public void init() throws IOException { + vec1 = new byte[size]; + vec2 = new byte[size]; + ThreadLocalRandom.current().nextBytes(vec1); + ThreadLocalRandom.current().nextBytes(vec2); + + dir = new MMapDirectory(Files.createTempDirectory("VectorScorerBenchmark")); + try (IndexOutput out = dir.createOutput("vector.data", IOContext.DEFAULT)) { + out.writeBytes(vec1, 0, vec1.length); + out.writeBytes(vec2, 0, vec2.length); + } + in = dir.openInput("vector.data", IOContext.DEFAULT); + vectorValues = vectorValues(size, 2, in); + scorer = + VectorizationProvider.getInstance() + .newFlatVectorScorer() + .getRandomVectorScorerSupplier(DOT_PRODUCT, vectorValues); + + // Ensure we're using the right vector scorer Review Comment: anyways if you have wrong cpu, also all other benchmark will be as fast as non-vectorized one. In this case the assertion just fails, but this is not strongly needed. We print a log message anyways if vectorization is enabled and you see this in the benchmark anyways. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org