ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/jtreg/util/TimSort/SortPerf.java
Revision: 1.3
Committed: Mon Jan 8 03:12:03 2018 UTC (6 years, 4 months ago) by jsr166
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +0 -2 lines
Log Message:
organize imports

File Contents

# Content
1 /*
2 * Copyright 2009 Google Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 public class SortPerf {
25 private static final int NUM_SETS = 5;
26 private static final int[] lengths = { 10, 100, 1000, 10000, 1000000 };
27
28 // Returns the number of repetitions as a function of the list length
29 private static int reps(int n) {
30 return (int) (12000000 / (n * Math.log10(n)));
31 }
32
33 public static void main(String[] args) {
34 Sorter.warmup();
35
36 System.out.print("Strategy,Length");
37 for (Sorter sorter : Sorter.values())
38 System.out.print("," + sorter);
39 System.out.println();
40
41 for (ArrayBuilder ab : ArrayBuilder.values()) {
42 for (int n : lengths) {
43 System.out.printf("%s,%d", ab, n);
44 int reps = reps(n);
45 Object[] proto = ab.build(n);
46 for (Sorter sorter : Sorter.values()) {
47 double minTime = Double.POSITIVE_INFINITY;
48 for (int set = 0; set < NUM_SETS; set++) {
49 long startTime = System.nanoTime();
50 for (int k = 0; k < reps; k++) {
51 Object[] a = proto.clone();
52 sorter.sort(a);
53 }
54 long endTime = System.nanoTime();
55 double time = (endTime - startTime) / (1000000. * reps);
56 minTime = Math.min(minTime, time);
57 }
58 System.out.printf(",%5f", minTime);
59 }
60 System.out.println();
61 }
62 }
63 }
64 }