1473N/A/*
1473N/A * Copyright 2009 Google Inc. All Rights Reserved.
1473N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1473N/A *
1473N/A * This code is free software; you can redistribute it and/or modify it
1473N/A * under the terms of the GNU General Public License version 2 only, as
1473N/A * published by the Free Software Foundation.
1473N/A *
1473N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1473N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1473N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1473N/A * version 2 for more details (a copy is included in the LICENSE file that
1473N/A * accompanied this code).
1473N/A *
1473N/A * You should have received a copy of the GNU General Public License version
1473N/A * 2 along with this work; if not, write to the Free Software Foundation,
1473N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1473N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1473N/A */
1473N/A
1473N/Aimport java.util.Arrays;
1473N/A
1473N/Apublic class SortPerf {
1473N/A private static final int NUM_SETS = 5;
1473N/A private static final int[] lengths = { 10, 100, 1000, 10000, 1000000 };
1473N/A
1473N/A // Returns the number of repetitions as a function of the list length
1473N/A private static int reps(int n) {
1473N/A return (int) (12000000 / (n * Math.log10(n)));
1473N/A }
1473N/A
1473N/A public static void main(String[] args) {
1473N/A Sorter.warmup();
1473N/A
1473N/A System.out.print("Strategy,Length");
1473N/A for (Sorter sorter : Sorter.values())
1473N/A System.out.print("," + sorter);
1473N/A System.out.println();
1473N/A
1473N/A for (ArrayBuilder ab : ArrayBuilder.values()) {
1473N/A for (int n : lengths) {
1473N/A System.out.printf("%s,%d", ab, n);
1473N/A int reps = reps(n);
1473N/A Object[] proto = ab.build(n);
1473N/A for (Sorter sorter : Sorter.values()) {
1473N/A double minTime = Double.POSITIVE_INFINITY;
1473N/A for (int set = 0; set < NUM_SETS; set++) {
1473N/A long startTime = System.nanoTime();
1473N/A for (int k = 0; k < reps; k++) {
1473N/A Object[] a = proto.clone();
1473N/A sorter.sort(a);
1473N/A }
1473N/A long endTime = System.nanoTime();
1473N/A double time = (endTime - startTime) / (1000000. * reps);
1473N/A minTime = Math.min(minTime, time);
1473N/A }
1473N/A System.out.printf(",%5f", minTime);
1473N/A }
1473N/A System.out.println();
1473N/A }
1473N/A }
1473N/A }
1473N/A}