Path: blob/master/test/micro/org/openjdk/bench/java/lang/StrictMathBench.java
41161 views
/*1* Copyright (c) 2021, Oracle and/or its affiliates. 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*/22package org.openjdk.bench.java.lang;2324import java.util.concurrent.TimeUnit;25import 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.OutputTimeUnit;31import org.openjdk.jmh.annotations.Scope;32import org.openjdk.jmh.annotations.State;33import org.openjdk.jmh.annotations.Warmup;3435@Warmup(iterations = 3, time = 5, timeUnit = TimeUnit.SECONDS)36@Measurement(iterations = 4, time = 5, timeUnit = TimeUnit.SECONDS)37@Fork(2)38@OutputTimeUnit(TimeUnit.MILLISECONDS)39@BenchmarkMode(Mode.Throughput)40@State(Scope.Thread)41public class StrictMathBench {4243public int int1 = 1, int2 = 2, int42 = 42, int5 = 5;44public long long1 = 1L, long2 = 2L, long747 = 747L, long13 = 13L;45public float float1 = 1.0f, float2 = 2.0f, floatNegative99 = -99.0f, float7 = 7.0f, eFloat = 2.718f;46public double double1 = 1.0d, double2 = 2.0d, double81 = 81.0d, doubleNegative12 = -12.0d, double4Dot1 = 4.1d;4748@Benchmark49public double absDouble() {50return StrictMath.abs(doubleNegative12);51}5253@Benchmark54public int absExactInt() {55return StrictMath.absExact(int2);56}5758@Benchmark59public long absExactLong() {60return StrictMath.absExact(long2);61}6263@Benchmark64public float absFloat() {65return StrictMath.abs(floatNegative99);66}6768@Benchmark69public int absInt() {70return StrictMath.abs(int42);71}7273@Benchmark74public long absLong() {75return StrictMath.abs(long13);76}7778@Benchmark79public double acosDouble() {80return StrictMath.acos(double1);81}8283@Benchmark84public int addExactInt() {85return StrictMath.addExact(int42, int5);86}8788@Benchmark89public long addExactLong() {90return StrictMath.addExact(long2, long13);91}9293@Benchmark94public double asinDouble() {95return StrictMath.asin(double1);96}9798@Benchmark99public double atanDouble() {100return StrictMath.atan(double1);101}102103@Benchmark104public double atan2Double() {105return StrictMath.atan2(double1, double2);106}107108@Benchmark109public double cbrt() {110return StrictMath.cbrt(double81);111}112113@Benchmark114public double ceilDouble() {115return StrictMath.ceil(double4Dot1);116}117118@Benchmark119public double copySignDouble() {120return StrictMath.copySign(double81, doubleNegative12);121}122123@Benchmark124public float copySignFloat() {125return StrictMath.copySign(floatNegative99, float1);126}127128@Benchmark129public double cosDouble() {130return StrictMath.cos(double1);131}132133@Benchmark134public double coshDouble() {135return StrictMath.cosh(double2);136}137138@Benchmark139public int decrementExactInt() {140return StrictMath.decrementExact(int42);141}142143@Benchmark144public long decrementExactLong() {145return StrictMath.decrementExact(long747);146}147148@Benchmark149public double expDouble() {150return StrictMath.exp(double4Dot1);151}152153@Benchmark154public double expm1() {155return StrictMath.expm1(doubleNegative12);156}157158@Benchmark159public double floorDouble() {160return StrictMath.floor(doubleNegative12);161}162163@Benchmark164public int floorDivIntInt() {165return StrictMath.floorDiv(int42, int5);166}167168@Benchmark169public long floorDivLongInt() {170return StrictMath.floorDiv(long747, int42);171}172173@Benchmark174public long floorDivLongLong() {175return StrictMath.floorDiv(long747, long13);176}177178@Benchmark179public int floorModIntInt() {180return StrictMath.floorMod(int42, int5);181}182183@Benchmark184public int floorModLongInt() {185return StrictMath.floorMod(long747, int5);186}187188@Benchmark189public long floorModLongLong() {190return StrictMath.floorMod(long747, long13);191}192193@Benchmark194public double fmaDouble() {195return StrictMath.fma(double2, double81, double4Dot1);196}197198@Benchmark199public float fmaFloat() {200return StrictMath.fma(float2, floatNegative99, float7);201}202203@Benchmark204public int getExponentDouble() {205return StrictMath.getExponent(double81);206}207208@Benchmark209public int getExponentFloat() {210return StrictMath.getExponent(float7);211}212213@Benchmark214public double hypotDouble() {215return StrictMath.hypot(double2, double4Dot1);216}217218@Benchmark219public double IEEERemainderDouble() {220return StrictMath.IEEEremainder(double81, double4Dot1);221}222223@Benchmark224public int IncrementExactInt() {225return StrictMath.incrementExact(int42);226}227228@Benchmark229public long IncrementExactLong() {230return StrictMath.incrementExact(long747);231}232233@Benchmark234public double logDouble() {235return StrictMath.log(double81);236}237238@Benchmark239public double log10Double() {240return StrictMath.log10(double81);241}242243@Benchmark244public double log1pDouble() {245return StrictMath.log1p(double81);246}247248@Benchmark249public int maxInt() {250return StrictMath.max(int1, int2);251}252253@Benchmark254public long maxLong() {255return StrictMath.max(long1, long2);256}257258@Benchmark259public float maxFloat() {260return StrictMath.max(float1, float2);261}262263@Benchmark264public double maxDouble() {265return StrictMath.max(double1, doubleNegative12);266}267268@Benchmark269public int minInt() {270return StrictMath.min(int1, int2);271}272273@Benchmark274public long minLong() {275return StrictMath.min(long1, long2);276}277278@Benchmark279public float minFloat() {280return StrictMath.min(float1, floatNegative99);281}282283@Benchmark284public double minDouble() {285return StrictMath.min(double4Dot1, double2);286}287288@Benchmark289public int multiplyExactInt() {290return StrictMath.multiplyExact(int42, int5);291}292293@Benchmark294public long multiplyExactLongInt() {295return StrictMath.multiplyExact(long747, int42);296}297298@Benchmark299public long multiplyExactLongLong() {300return StrictMath.multiplyExact(long747, long13);301}302303@Benchmark304public long multiplyFullIntInt() {305return StrictMath.multiplyFull(int42, int5);306}307308@Benchmark309public long multiplyHighLongLog() {310return StrictMath.multiplyHigh(long747, long13);311}312313@Benchmark314public int negateExactInt() {315return StrictMath.negateExact(int42);316}317318@Benchmark319public long negateExactLong() {320return StrictMath.negateExact(long747);321}322323@Benchmark324public double nextAfterDoubleDouble() {325return StrictMath.nextAfter(double81, double4Dot1);326}327328@Benchmark329public float nextAfterFloatDouble() {330return StrictMath.nextAfter(float7, doubleNegative12);331}332333@Benchmark334public double nextDownDouble() {335return StrictMath.nextDown(float7);336}337338@Benchmark339public float nextDownFloat() {340return StrictMath.nextDown(floatNegative99);341}342343@Benchmark344public double nextUpDouble() {345return StrictMath.nextUp(double81);346}347348@Benchmark349public float nextUpFloat() {350return StrictMath.nextUp(float7);351}352353@Benchmark354public double powDouble() {355return StrictMath.pow(double4Dot1, double2);356}357358@Benchmark359public double random() {360return StrictMath.random();361}362363@Benchmark364public double rintDouble() {365return StrictMath.rint(double4Dot1);366}367368@Benchmark369public long roundDouble() {370return StrictMath.round( StrictMath.PI);371}372373@Benchmark374public int roundFloat() {375return StrictMath.round(eFloat);376}377378@Benchmark379public double scalbDoubleInt() {380return StrictMath.scalb(double81, int2);381}382383@Benchmark384public float scalbFloatInt() {385return StrictMath.scalb(float7, int2);386}387388@Benchmark389public double sigNumDouble() {390return StrictMath.signum(double4Dot1);391}392393@Benchmark394public double signumFloat() {395return StrictMath.signum(floatNegative99);396}397398@Benchmark399public double sinDouble() {400return StrictMath.sin(double1);401}402403@Benchmark404public double sinhDouble() {405return StrictMath.sinh(double4Dot1);406}407408@Benchmark409public double sqrtDouble() {410return StrictMath.sqrt(double4Dot1);411}412413@Benchmark414public double subtractExactIntInt() {415return StrictMath.subtractExact(int42,int5);416}417418@Benchmark419public double subtractExactLongLong() {420return StrictMath.subtractExact(long747,long13);421}422423@Benchmark424public double tanDouble() {425return StrictMath.tan(double1);426}427428@Benchmark429public double tanhDouble() {430return StrictMath.tanh(double1);431}432433@Benchmark434public double toDegreesDouble() {435return StrictMath.toDegrees(double81);436}437438@Benchmark439public double toIntExactLong() {440return StrictMath.toIntExact(long747);441}442443@Benchmark444public double toRadiansDouble() {445return StrictMath.toRadians(double81);446}447448@Benchmark449public double ulpDouble() {450return StrictMath.ulp(double4Dot1);451}452453@Benchmark454public double ulpFloat() {455return StrictMath.ulp(float7);456}457458}459460461