test/micro/org/openjdk/bench/java/math/BigDecimals.java
author coleenp
Tue, 27 Nov 2018 19:46:57 -0500
changeset 52705 53a407ab6d22
parent 52595 16609197022c
permissions -rw-r--r--
8214151: [TESTBUG] CleanProtectionDomain.java fails due to RuntimeException: 'protection domain unlinked' missing Summary: call WB_ProtectionDomainRemovedCount. Reviewed-by: jiangli, pchilanomate
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52595
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
     1
/*
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
     2
 * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
     4
 *
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
     7
 * published by the Free Software Foundation.
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
     8
 *
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    13
 * accompanied this code).
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    14
 *
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    18
 *
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    21
 * questions.
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    22
 */
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    23
package org.openjdk.bench.java.math;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    24
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    25
import org.openjdk.jmh.annotations.Benchmark;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    26
import org.openjdk.jmh.annotations.BenchmarkMode;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    27
import org.openjdk.jmh.annotations.Mode;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    28
import org.openjdk.jmh.annotations.OperationsPerInvocation;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    29
import org.openjdk.jmh.annotations.OutputTimeUnit;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    30
import org.openjdk.jmh.annotations.Scope;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    31
import org.openjdk.jmh.annotations.Setup;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    32
import org.openjdk.jmh.annotations.State;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    33
import org.openjdk.jmh.infra.Blackhole;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    34
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    35
import java.math.BigDecimal;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    36
import java.util.Random;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    37
import java.util.concurrent.TimeUnit;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    38
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    39
@BenchmarkMode(Mode.AverageTime)
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    40
@OutputTimeUnit(TimeUnit.NANOSECONDS)
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    41
@State(Scope.Thread)
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    42
public class BigDecimals {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    43
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    44
    /** Make sure TEST_SIZE is used to size the arrays. We need this constant to parametrize the operations count. */
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    45
    private static final int TEST_SIZE = 100;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    46
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    47
    /* dummy variables for intermediate results */
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    48
    public Object[] dummyArr;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    49
    public String[] dummyStringArray;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    50
    public int dummy;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    51
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    52
    /* array to hold the created objects. */
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    53
    private BigDecimal[] bigDecimals;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    54
    private String[] stringInputs;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    55
    private double[] doubleInputs;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    56
    private BigDecimal[] hugeArray, largeArray, smallArray;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    57
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    58
    @Setup
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    59
    public void setup() {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    60
        Random r = new Random(1123);
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    61
        dummyArr = new Object[TEST_SIZE];
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    62
        bigDecimals = new BigDecimal[TEST_SIZE];
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    63
        stringInputs = new String[TEST_SIZE];
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    64
        doubleInputs = new double[TEST_SIZE];
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    65
        for (int i = 0; i < TEST_SIZE; i++) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    66
            double value = (double) (i + 1);
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    67
            switch (i % 4) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    68
                case 0:
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    69
                    value = -value * 54345.0d;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    70
                    break;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    71
                case 1:
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    72
                    value = value * 5434543453454355e100;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    73
                    break;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    74
                case 2:
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    75
                    value = -value / 5434543453454355e100;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    76
                    break;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    77
                case 3:
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    78
                    break;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    79
            }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    80
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    81
            bigDecimals[i] = new BigDecimal(value);
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    82
            stringInputs[i] = "" + value;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    83
            doubleInputs[i] = value;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    84
        }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    85
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    86
        /*
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    87
         * Huge numbers larger than MAX_LONG
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    88
         */
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    89
        hugeArray = new BigDecimal[TEST_SIZE];
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    90
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    91
        /*
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    92
        * Large numbers less than MAX_LONG but larger than MAX_INT
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    93
        */
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    94
        largeArray = new BigDecimal[TEST_SIZE];
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    95
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    96
        /*
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    97
        * Small number less than MAX_INT
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    98
        */
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
    99
        smallArray = new BigDecimal[TEST_SIZE];
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   100
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   101
        dummyStringArray = new String[TEST_SIZE];
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   102
        for (int i = 0; i < TEST_SIZE; i++) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   103
            int value = Math.abs(r.nextInt());
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   104
            hugeArray[i] = new BigDecimal("" + ((long) value + (long) Integer.MAX_VALUE)
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   105
                    + ((long) value + (long) Integer.MAX_VALUE) + ".55");
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   106
            largeArray[i] = new BigDecimal("" + ((long) value + (long) Integer.MAX_VALUE) + ".55");
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   107
            smallArray[i] = new BigDecimal("" + ((long) value / 1000) + ".55");
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   108
        }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   109
    }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   110
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   111
    /** Invokes the (String)-constructor of BigDecimal with various different values. */
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   112
    @Benchmark
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   113
    @OperationsPerInvocation(TEST_SIZE)
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   114
    public void testConstructorWithString(Blackhole bh) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   115
        for (String s : stringInputs) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   116
            bh.consume(new BigDecimal(s));
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   117
        }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   118
    }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   119
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   120
    /** Invokes the (double)-constructor of BigDecimal with various different values. */
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   121
    @Benchmark
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   122
    @OperationsPerInvocation(TEST_SIZE)
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   123
    public void testConstructorWithDouble(Blackhole bh) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   124
        for (double s : doubleInputs) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   125
            bh.consume(new BigDecimal(s));
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   126
        }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   127
    }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   128
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   129
    /** Invokes the toString method of BigDecimal with various different values. */
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   130
    @Benchmark
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   131
    @OperationsPerInvocation(TEST_SIZE)
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   132
    public void testToString(Blackhole bh) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   133
        for (BigDecimal s : bigDecimals) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   134
            bh.consume(s.toString());
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   135
        }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   136
    }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   137
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   138
    /**
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   139
     * Invokes the setScale method of BigDecimal with various different values.
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   140
     */
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   141
    @Benchmark
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   142
    @OperationsPerInvocation(TEST_SIZE)
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   143
    public void testSetScale(Blackhole bh) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   144
        for (BigDecimal s : bigDecimals) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   145
            bh.consume(s.setScale(2, BigDecimal.ROUND_HALF_UP));
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   146
        }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   147
    }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   148
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   149
    /** Invokes the setScale method of BigDecimal with various different values. */
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   150
    @Benchmark
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   151
    @OperationsPerInvocation(50 * TEST_SIZE)
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   152
    public void testSetScaleVarious(Blackhole bh) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   153
        for (int scale = 0; scale < 50; scale++) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   154
            for (BigDecimal s : bigDecimals) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   155
                bh.consume(s.setScale(scale, BigDecimal.ROUND_HALF_UP));
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   156
            }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   157
        }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   158
    }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   159
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   160
    /** Invokes the add method of BigDecimal with various different values. */
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   161
    @Benchmark
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   162
    @OperationsPerInvocation(TEST_SIZE)
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   163
    public void testAdd(Blackhole bh) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   164
        BigDecimal tmp = null;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   165
        for (BigDecimal s : bigDecimals) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   166
            if (tmp == null) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   167
                tmp = s;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   168
                continue;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   169
            }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   170
            tmp = tmp.add(s);
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   171
        }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   172
        bh.consume(tmp);
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   173
    }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   174
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   175
    /** Invokes the multiply method of BigDecimal with various different values. */
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   176
    @Benchmark
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   177
    @OperationsPerInvocation(TEST_SIZE)
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   178
    public void testMultiply(Blackhole bh) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   179
        BigDecimal tmp = null;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   180
        for (BigDecimal s : bigDecimals) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   181
            if (tmp == null) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   182
                tmp = s;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   183
                continue;
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   184
            }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   185
            tmp = tmp.multiply(s);
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   186
        }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   187
        bh.consume(tmp);
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   188
    }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   189
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   190
    /** Invokes the compareTo method of BigDecimal with various different values. */
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   191
    @Benchmark
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   192
    @OperationsPerInvocation(TEST_SIZE - 1)
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   193
    public void testCompareTo(Blackhole bh) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   194
        BigDecimal c = bigDecimals[0];
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   195
        for (BigDecimal s : bigDecimals) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   196
            bh.consume(c.compareTo(s));
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   197
        }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   198
    }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   199
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   200
    /** Test BigDecimal.toString() with huge numbers larger than MAX_LONG */
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   201
    @Benchmark
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   202
    @OperationsPerInvocation(TEST_SIZE)
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   203
    public void testHugeToString(Blackhole bh) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   204
        for (BigDecimal s : hugeArray) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   205
            bh.consume(s.toString());
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   206
        }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   207
    }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   208
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   209
    /** Test BigDecimal.toString() with large numbers less than MAX_LONG but larger than MAX_INT */
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   210
    @Benchmark
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   211
    @OperationsPerInvocation(TEST_SIZE)
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   212
    public void testLargeToString(Blackhole bh) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   213
        for (BigDecimal s : largeArray) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   214
            bh.consume(s.toString());
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   215
        }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   216
    }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   217
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   218
    /** Test BigDecimal.toString() with small numbers less than MAX_INT */
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   219
    @Benchmark
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   220
    @OperationsPerInvocation(TEST_SIZE)
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   221
    public void testSmallToString(Blackhole bh) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   222
        for (BigDecimal s : smallArray) {
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   223
            bh.consume(s.toString());
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   224
        }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   225
    }
16609197022c 8061281: Microbenchmark suite build support, directory layout and sample benchmarks
redestad
parents:
diff changeset
   226
}