Mercurial > hg > gc-bench
view src/main/java/org/openjdk/gcbench/tests/Sequence.java @ 88:583fef4276f5
Update license and copyright headers.
author | shade |
---|---|
date | Wed, 22 Nov 2017 15:58:02 +0100 |
parents | f321fbdd1093 |
children |
line wrap: on
line source
/* * Copyright (c) 2017, Red Hat Inc. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package org.openjdk.gcbench.tests; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.stream.Collectors; public class Sequence implements Iterable<Object> { private final String descr; private final List<Object> vals; public static Sequence powersOfTen_Sub(int min, int max) { List<Object> vs = new ArrayList<>(); for (int v = min; v <= max; v *= 10) { for (int t = 1; t <= 5; t++) { int n = v * t * 2; if (n <= max) { vs.add(n); } } } return new Sequence("[" + min + ", " + max + "], power-of-ten steps, last step divided in 5 parts", vs); } public static Sequence powersOfTen_Sub10(int min, int max) { List<Object> vs = new ArrayList<>(); for (int v = min; v <= max; v *= 10) { for (int t = 1; t < 10; t++) { int n = v * t; if (n <= max) { vs.add(n); } } } return new Sequence("[" + min + ", " + max + "], power-of-ten steps, last step divided in 10 parts", vs); } public static Sequence equidistantLog(int min, int max, int steps) { List<Object> vs = new ArrayList<>(); double minLog = Math.log(min); double maxLog = Math.log(max); for (int c = 0; c <= steps; c++) { double v = minLog + (maxLog - minLog) * c / steps; vs.add((int)Math.exp(v)); } return new Sequence("[" + min + ", " + max + "], equidistant, " + steps + " steps", vs); } public static Sequence powersOfTen(int min, int max) { List<Object> vs = new ArrayList<>(); for (int v = min; v <= max; v *= 10) { vs.add(v); } return new Sequence("[" + min + ", " + max + "], power-of-ten steps", vs); } public static Sequence powersOfTwo(int min, int max) { List<Object> vs = new ArrayList<>(); for (int v = min; v <= max; v *= 2) { vs.add(v); } return new Sequence("[" + min + ", " + max + "], power-of-two steps", vs); } public static Sequence powersOfTwo_WithMax(int min, int max) { List<Object> vs = new ArrayList<>(); for (int v = min; v < max; v *= 2) { vs.add(v); } vs.add(max); return new Sequence("[" + min + ", " + max + "], power-of-two steps, with additional max", vs); } public static Sequence steps(int min, int max, int steps) { List<Object> vs = new ArrayList<>(); int stepSize = (max - min) / steps; for (int v = min; v <= max; v += stepSize) { vs.add(v); } return new Sequence("[" + min + ", " + max + "], step size = " + stepSize, vs); } public static Sequence predefined(int... values) { return new Sequence(Arrays.toString(values), Arrays.stream(values).boxed().collect(Collectors.toList())); } public static Sequence predefined(List<Integer> values) { return new Sequence(values.toString(), new ArrayList<>(values)); } private Sequence(String descr, List<Object> vals) { this.descr = descr; this.vals = vals; } @Override public Iterator<Object> iterator() { return vals.iterator(); } @Override public String toString() { return descr; } public static Sequence jvmModes() { return new Sequence("available JVM modes", Arrays.asList( "-Xint", "-XX:TieredStopAtLevel=1", // "-XX:TieredStopAtLevel=2", // "-XX:TieredStopAtLevel=3", "-XX:TieredStopAtLevel=4" )); } public static Sequence javaType() { return new Sequence("Java types", Arrays.asList( "none", "boolean", "byte", "short", "char", "int", "float", "long", "double", "Object" )); } }