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