Path: blob/master/test/micro/org/openjdk/bench/java/math/FpRoundingBenchmark.java
41161 views
//1// Copyright (c) 2003, 2019, 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//22//23package org.openjdk.bench.java.math;2425import java.util.Random;26import java.util.concurrent.TimeUnit;27import org.openjdk.jmh.annotations.*;28import org.openjdk.jmh.infra.Blackhole;2930@OutputTimeUnit(TimeUnit.MILLISECONDS)31@State(Scope.Thread)32public class FpRoundingBenchmark {3334@Param({"1024"})35public int TESTSIZE;3637public double[] DargV1;3839public double[] Res;4041public final double[] DspecialVals = {420.0, -0.0, Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY};4344@Setup(Level.Trial)45public void BmSetup() {46int i = 0;47Random r = new Random(1024);48DargV1 = new double[TESTSIZE];49Res = new double[TESTSIZE];5051for (; i < DspecialVals.length; i++) {52DargV1[i] = DspecialVals[i];53}5455for (; i < TESTSIZE; i++) {56DargV1[i] = r.nextDouble()*TESTSIZE;57}58}5960@Benchmark61public void testceil(Blackhole bh) {62for (int i = 0; i < TESTSIZE; i++)63Res[i] = Math.ceil(DargV1[i]);64}6566@Benchmark67public void testfloor(Blackhole bh) {68for (int i = 0; i < TESTSIZE; i++)69Res[i] = Math.floor(DargV1[i]);70}7172@Benchmark73public void testrint(Blackhole bh) {74for (int i = 0; i < TESTSIZE; i++)75Res[i] = Math.rint(DargV1[i]);76}77}787980