bruno-roustant commented on a change in pull request #404: URL: https://github.com/apache/lucene/pull/404#discussion_r734039059
########## File path: lucene/core/src/test/org/apache/lucene/util/SorterBenchmark.java ########## @@ -0,0 +1,129 @@ +/* + * 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.util; + +import java.util.Random; +import org.apache.lucene.util.BaseSortTestCase.Entry; +import org.apache.lucene.util.BaseSortTestCase.Strategy; + +/** + * Benchmark for {@link Sorter} implementations. + * + * <p>Run the static {@link #main(String[])} method to start the benchmark. + */ +public class SorterBenchmark { + + private static final int ARRAY_LENGTH = 20000; + private static final int RUNS = 10; + private static final int LOOPS = 100; + + private enum SorterFactory { + INTRO_SORTER( + "IntroSorter", + (arr, s) -> { + return new ArrayIntroSorter<>(arr, Entry::compareTo); + }), + TIM_SORTER( + "TimSorter", + (arr, s) -> { + return new ArrayTimSorter<>(arr, Entry::compareTo, arr.length / 64); + }), + MERGE_SORTER( + "MergeSorter", + (arr, s) -> { + return new ArrayInPlaceMergeSorter<>(arr, Entry::compareTo); + }), + ; + final String name; + final Builder builder; + + SorterFactory(String name, Builder builder) { + this.name = name; + this.builder = builder; + } + + interface Builder { + Sorter build(Entry[] arr, Strategy strategy); + } + } + + public static void main(String[] args) throws Exception { Review comment: Can we disable the assertions when running a test? (yes I hesitated to go with JMH but indeed I kept it simple, and based on the many runs I saw, the ratio between the sorters is reproducible) -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
