test/micro/org/openjdk/bench/java/util/ArraysFill.java
author ecaspole
Wed, 02 Jan 2019 13:37:55 -0500
changeset 53126 3d0f6ef91216
permissions -rw-r--r--
8215572: Add new Arrays micros Summary: New micros for mismatch and fill Reviewed-by: kvn, vlivanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
53126
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
     1
/*
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
     4
 *
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
     8
 *
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    13
 * accompanied this code).
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    14
 *
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    18
 *
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    21
 * questions.
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    22
 */
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    23
package org.openjdk.bench.java.util;
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    24
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    25
import org.openjdk.jmh.annotations.Benchmark;
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    26
import org.openjdk.jmh.annotations.BenchmarkMode;
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    27
import org.openjdk.jmh.annotations.Measurement;
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    28
import org.openjdk.jmh.annotations.Mode;
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    29
import org.openjdk.jmh.annotations.OutputTimeUnit;
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    30
import org.openjdk.jmh.annotations.Param;
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    31
import org.openjdk.jmh.annotations.Scope;
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    32
import org.openjdk.jmh.annotations.Setup;
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    33
import org.openjdk.jmh.annotations.State;
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    34
import org.openjdk.jmh.annotations.Warmup;
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    35
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    36
import java.util.Arrays;
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    37
import java.util.concurrent.TimeUnit;
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    38
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    39
@BenchmarkMode(Mode.AverageTime)
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    40
@OutputTimeUnit(TimeUnit.NANOSECONDS)
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    41
@State(Scope.Thread)
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    42
public class ArraysFill {
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    43
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    44
    @Param({"10", "266", "2048"})
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    45
    public int size;
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    46
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    47
    public byte[] testByteArray;
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    48
    public char[] testCharArray;
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    49
    public short[] testShortArray;
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    50
    public int[] testIntArray;
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    51
    public long[] testLongArray;
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    52
    public float[] testFloatArray;
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    53
    public double[] testDoubleArray;
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    54
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    55
    @Setup
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    56
    public void setup() {
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    57
        testByteArray = new byte[size];
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    58
        testCharArray = new char[size];
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    59
        testShortArray = new short[size];
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    60
        testIntArray = new int[size];
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    61
        testLongArray = new long[size];
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    62
        testFloatArray = new float[size];
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    63
        testDoubleArray = new double[size];
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    64
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    65
    }
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    66
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    67
    @Benchmark
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    68
    @Warmup(iterations = 3)
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    69
    @Measurement(iterations = 3)
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    70
    public void testCharFill() {
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    71
        Arrays.fill(testCharArray, (char) -1);
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    72
    }
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    73
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    74
    @Benchmark
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    75
    @Warmup(iterations = 3)
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    76
    @Measurement(iterations = 3)
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    77
    public void testByteFill() {
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    78
        Arrays.fill(testByteArray, (byte) -1);
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    79
    }
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    80
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    81
    @Benchmark
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    82
    @Warmup(iterations = 3)
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    83
    @Measurement(iterations = 3)
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    84
    public void testShortFill() {
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    85
        Arrays.fill(testShortArray, (short) -1);
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    86
    }
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    87
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    88
    @Benchmark
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    89
    @Warmup(iterations = 3)
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    90
    @Measurement(iterations = 3)
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    91
    public void testIntFill() {
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    92
        Arrays.fill(testIntArray, -1);
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    93
    }
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    94
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    95
    @Benchmark
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    96
    @Warmup(iterations = 3)
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    97
    @Measurement(iterations = 3)
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    98
    public void testLongFill() {
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
    99
        Arrays.fill(testLongArray, -1);
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
   100
    }
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
   101
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
   102
    @Benchmark
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
   103
    @Warmup(iterations = 3)
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
   104
    @Measurement(iterations = 3)
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
   105
    public void testFloatFill() {
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
   106
        Arrays.fill(testFloatArray, (float) -1.0);
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
   107
    }
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
   108
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
   109
    @Benchmark
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
   110
    @Warmup(iterations = 3)
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
   111
    @Measurement(iterations = 3)
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
   112
    public void testDoubleFill() {
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
   113
        Arrays.fill(testDoubleArray, -1.0);
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
   114
    }
3d0f6ef91216 8215572: Add new Arrays micros
ecaspole
parents:
diff changeset
   115
}