Path: blob/master/test/micro/org/openjdk/bench/vm/compiler/Signum.java
41161 views
/*1* Copyright (c) Intel, 2021 All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package org.openjdk.bench.vm.compiler;2425import org.openjdk.jmh.annotations.Benchmark;26import org.openjdk.jmh.annotations.BenchmarkMode;27import org.openjdk.jmh.annotations.Fork;28import org.openjdk.jmh.annotations.Measurement;29import org.openjdk.jmh.annotations.Mode;30import org.openjdk.jmh.annotations.OperationsPerInvocation;31import org.openjdk.jmh.annotations.OutputTimeUnit;32import org.openjdk.jmh.annotations.Scope;33import org.openjdk.jmh.annotations.State;34import org.openjdk.jmh.annotations.Warmup;35import org.openjdk.jmh.infra.Blackhole;3637import java.util.concurrent.TimeUnit;3839@BenchmarkMode(Mode.AverageTime)40@OutputTimeUnit(TimeUnit.NANOSECONDS)41@State(Scope.Thread)42@Warmup(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)43@Measurement(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS)44@Fork(3)45public class Signum {4647private final int ITERATIONS = 15000;4849private double doubleValue = 1D;50private float floatValue = 1F;5152private static final float[] float_values = {53123.4f,54-56.7f,557e30f,56-0.3e30f,57Float.MAX_VALUE,58-Float.MAX_VALUE,59Float.MIN_VALUE,60-Float.MIN_VALUE,610.0f,62-0.0f,63Float.POSITIVE_INFINITY,64Float.NEGATIVE_INFINITY,65Float.NaN,66Float.MIN_NORMAL,67-Float.MIN_NORMAL,680x0.0002P-126f,69-0x0.0002P-126f70};7172private static final double[] double_values = {73123.4d,74-56.7d,757e30d,76-0.3e30d,77Double.MAX_VALUE,78-Double.MAX_VALUE,79Double.MIN_VALUE,80-Double.MIN_VALUE,810.0d,82-0.0d,83Double.POSITIVE_INFINITY,84Double.NEGATIVE_INFINITY,85Double.NaN,86Double.MIN_NORMAL,87-Double.MIN_NORMAL,880x0.00000001P-1022,89-0x0.00000001P-1022,90};9192private static double Signum_Kernel(double data)93{94return Math.signum(data);95}9697private static float Signum_Kernel(float data)98{99return Math.signum(data);100}101102@Benchmark103@OperationsPerInvocation(ITERATIONS * 17)104public void _1_signumFloatTest(Blackhole bh) {105for (int i = 0; i < ITERATIONS; i++) {106for (float f : float_values) {107bh.consume(Signum_Kernel(f));108}109}110}111112@Benchmark113@OperationsPerInvocation(ITERATIONS * 17)114public void _2_overheadFloat(Blackhole bh) {115for (int i = 0; i < ITERATIONS; i++) {116for (float f : float_values) {117bh.consume(f);118}119}120}121122@Benchmark123@OperationsPerInvocation(ITERATIONS * 17)124public void _3_signumDoubleTest(Blackhole bh) {125for (int i = 0; i < ITERATIONS; i++) {126for (double d : double_values) {127bh.consume(Signum_Kernel(d));128}129}130}131132@Benchmark133@OperationsPerInvocation(ITERATIONS * 17)134public void _4_overheadDouble(Blackhole bh) {135for (int i = 0; i < ITERATIONS; i++) {136for (double d : double_values) {137bh.consume(d);138}139}140}141}142143144