/*
* Copyright ( c ) Intel , 2021 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 .
*
* 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.bench.vm.compiler;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
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.State;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;
import java.util.concurrent.TimeUnit;
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Thread )
@Warmup(iterations = 4 , time = 2 , timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 4 , time = 2 , timeUnit = TimeUnit.SECONDS)
@Fork(value = 3 )
public class Signum {
private final int ITERATIONS = 15000 ;
private double doubleValue = 1 D;
private float floatValue = 1 F;
private static final float [] float_values = {
123 .4 f,
-56 .7 f,
7 e30f,
-0 .3 e30f,
Float .MAX_VALUE,
-Float .MAX_VALUE,
Float .MIN_VALUE,
-Float .MIN_VALUE,
0 .0 f,
-0 .0 f,
Float .POSITIVE_INFINITY,
Float .NEGATIVE_INFINITY,
Float .NaN,
Float .MIN_NORMAL,
-Float .MIN_NORMAL,
0 x0.0002 P-126 f,
-0 x0.0002 P-126 f
};
private static final double [] double_values = {
123 .4 d,
-56 .7 d,
7 e30d,
-0 .3 e30d,
Double .MAX_VALUE,
-Double .MAX_VALUE,
Double .MIN_VALUE,
-Double .MIN_VALUE,
0 .0 d,
-0 .0 d,
Double .POSITIVE_INFINITY,
Double .NEGATIVE_INFINITY,
Double .NaN,
Double .MIN_NORMAL,
-Double .MIN_NORMAL,
0 x0.00000001 P-1022 ,
-0 x0.00000001 P-1022 ,
};
private static double Signum_Kernel(double data)
{
return Math.signum(data);
}
private static float Signum_Kernel(float data)
{
return Math.signum(data);
}
private static double Copysign_Kernel(double data, double sign)
{
return Math.copySign(data, sign);
}
private static float Copysign_Kernel(float data, float sign)
{
return Math.copySign(data, sign);
}
@Benchmark
@OperationsPerInvocation(ITERATIONS * 17 )
public void _1 _signumFloatTest(Blackhole bh) {
for (int i = 0 ; i < ITERATIONS; i++) {
for (float f : float_values) {
bh.consume(Signum_Kernel(f));
}
}
}
@Benchmark
@OperationsPerInvocation(ITERATIONS * 17 )
public void _2 _overheadFloat(Blackhole bh) {
for (int i = 0 ; i < ITERATIONS; i++) {
for (float f : float_values) {
bh.consume(f);
}
}
}
@Benchmark
@OperationsPerInvocation(ITERATIONS * 17 )
public void _3 _signumDoubleTest(Blackhole bh) {
for (int i = 0 ; i < ITERATIONS; i++) {
for (double d : double_values) {
bh.consume(Signum_Kernel(d));
}
}
}
@Benchmark
@OperationsPerInvocation(ITERATIONS * 17 )
public void _4 _overheadDouble(Blackhole bh) {
for (int i = 0 ; i < ITERATIONS; i++) {
for (double d : double_values) {
bh.consume(d);
}
}
}
@Benchmark
@OperationsPerInvocation(ITERATIONS * 17 )
public void _5 _copySignFloatTest(Blackhole bh) {
for (int i = 0 ; i < ITERATIONS; i++) {
for (float f : float_values) {
bh.consume(Copysign_Kernel(floatValue, f));
}
}
}
@Benchmark
@OperationsPerInvocation(ITERATIONS * 17 )
public void _6 _overheadCopySignFloat(Blackhole bh) {
for (int i = 0 ; i < ITERATIONS; i++) {
for (float f : float_values) {
bh.consume(f);
}
}
}
@Benchmark
@OperationsPerInvocation(ITERATIONS * 17 )
public void _7 _copySignDoubleTest(Blackhole bh) {
for (int i = 0 ; i < ITERATIONS; i++) {
for (double d : double_values) {
bh.consume(Copysign_Kernel(doubleValue, d));
}
}
}
@Benchmark
@OperationsPerInvocation(ITERATIONS * 17 )
public void _8 _overheadCopySignDouble(Blackhole bh) {
for (int i = 0 ; i < ITERATIONS; i++) {
for (double d : double_values) {
bh.consume(d);
}
}
}
}
Messung V0.5 in Prozent C=96 H=96 G=95
¤ Dauer der Verarbeitung: 0.5 Sekunden
¤
*© Formatika GbR, Deutschland