<commit_before><commit_msg>Add JMH performance tests for IndexSorter implementation.<commit_after>/*
 * Java Genetic Algorithm Library (@__identifier__@).
 * Copyright (c) @__year__@ <NAME>
 *
 * Licensed 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.
 *
 * Author:
 *    <NAME> (<EMAIL>)
 */
package org.jenetics.internal.util;

import java.util.Random;
import java.util.concurrent.TimeUnit;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version 3.0 &mdash; <em>$Date: 2014-08-11 $</em>
 * @since 3.0
 */
@State(Scope.Benchmark)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public class IndexSorterPerf {

	private double[] array20 = new Random().doubles(20).toArray();
	private double[] array40 = new Random().doubles(40).toArray();
	private double[] array80 = new Random().doubles(80).toArray();
	private double[] array160 = new Random().doubles(160).toArray();
	private double[] array250 = new Random().doubles(250).toArray();
	private double[] array320 = new Random().doubles(320).toArray();


	@Setup(Level.Invocation)
	public void shuffle() {
		arrays.shuffle(array20);
		arrays.shuffle(array40);
		arrays.shuffle(array80);
		arrays.shuffle(array160);
		arrays.shuffle(array250);
		arrays.shuffle(array320);
	}

	//@Benchmark
	public int insertionSort20() {
		return IndexSorter.INSERTION_SORTER.sort(array20, arrays.indexes(20))[0];
	}

	//@Benchmark
	public int insertionSort40() {
		return IndexSorter.INSERTION_SORTER.sort(array40, arrays.indexes(40))[0];
	}

	@Benchmark
	public int insertionSort80() {
		return IndexSorter.INSERTION_SORTER.sort(array80, arrays.indexes(80))[0];
	}

	@Benchmark
	public int insertionSort160() {
		return IndexSorter.INSERTION_SORTER.sort(array160, arrays.indexes(160))[0];
	}

	@Benchmark
	public int insertionSort250() {
		return IndexSorter.INSERTION_SORTER.sort(array250, arrays.indexes(250))[0];
	}

	@Benchmark
	public int insertionSort320() {
		return IndexSorter.INSERTION_SORTER.sort(array320, arrays.indexes(320))[0];
	}

	//@Benchmark
	public int heapSort20() {
		return IndexSorter.HEAP_SORTER.sort(array20, arrays.indexes(20))[0];
	}

	//@Benchmark
	public int heapSort40() {
		return IndexSorter.HEAP_SORTER.sort(array40, arrays.indexes(40))[0];
	}

	@Benchmark
	public int heapSort80() {
		return IndexSorter.HEAP_SORTER.sort(array80, arrays.indexes(80))[0];
	}

	@Benchmark
	public int heapSort160() {
		return IndexSorter.HEAP_SORTER.sort(array160, arrays.indexes(160))[0];
	}

	@Benchmark
	public int heapSort250() {
		return IndexSorter.HEAP_SORTER.sort(array250, arrays.indexes(250))[0];
	}

	@Benchmark
	public int heapSort320() {
		return IndexSorter.HEAP_SORTER.sort(array320, arrays.indexes(320))[0];
	}

	public static void main(String[] args) throws RunnerException {
		final Options opt = new OptionsBuilder()
			.include(".*" + IndexSorterPerf.class.getSimpleName() + ".*")
			.warmupIterations(7)
			.measurementIterations(14)
			.threads(1)
			.forks(1)
			.build();

		new Runner(opt).run();
	}

}
{'fraction_non_alphanumeric': 0.13437195715676728, 'fraction_numerical': 0.04089581304771178, 'mean_word_length': 5.105497771173848, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1567296', 'n_tokens_mistral': 1596, 'n_tokens_neox': 1415, 'n_words': 291}