gf2121 commented on code in PR #12800: URL: https://github.com/apache/lucene/pull/12800#discussion_r1391150384
########## lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/DocSorterBenchmark.java: ########## @@ -0,0 +1,241 @@ +/* + * 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 java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import org.apache.lucene.util.ArrayUtil; +import org.apache.lucene.util.BaseLSBRadixSorter; +import org.apache.lucene.util.IntsRef; +import org.apache.lucene.util.LongsRef; +import org.apache.lucene.util.TimSorter; +import org.apache.lucene.util.packed.PackedInts; +import org.openjdk.jmh.annotations.*; + +@BenchmarkMode(Mode.Throughput) +@OutputTimeUnit(TimeUnit.MILLISECONDS) +@State(Scope.Benchmark) +// first iteration is complete garbage, so make sure we really warmup +@Warmup(iterations = 3, 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 = 1, + jvmArgsAppend = {"-Xmx2g", "-Xms2g", "-XX:+AlwaysPreTouch"}) +public class DocSorterBenchmark { + + private DocOffsetTimSorter timSorter; + private DocOffsetRadixSorter radixSorter; + + @Param({"100000"}) + int size; + + @Param({"natural", "reverse", "random", "partial"}) + String order; + + @Param({"24", "31"}) + int bit; + + @Setup(Level.Invocation) + public void init() { + ThreadLocalRandom random = ThreadLocalRandom.current(); + + int maxDoc = 1 << (bit - 1); + assert PackedInts.bitsRequired(maxDoc) == bit; + // random byte arrays for binary methods + int[] doc = new int[size]; + long[] off = new long[size]; + for (int i = 0; i < size; ++i) { + doc[i] = random.nextInt(maxDoc); + off[i] = random.nextLong(Long.MAX_VALUE); + } + + switch (order) { + case "natural" -> Arrays.sort(doc); + case "reverse" -> { + List<Integer> docs = Arrays.stream(doc).sorted().boxed().collect(Collectors.toList()); + Collections.reverse(docs); + doc = docs.stream().mapToInt(i -> i).toArray(); + } Review Comment: > Or did java make that unnecessary at some point? Yes! The `->` switch expression will not fall though, see [JEP 361](https://openjdk.org/jeps/361). -- 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