Path: blob/master/test/micro/org/openjdk/bench/vm/compiler/ArrayFill.java
41161 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2020, Arm Limited. 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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324package org.openjdk.bench.vm.compiler;2526import org.openjdk.jmh.annotations.Benchmark;27import org.openjdk.jmh.annotations.BenchmarkMode;28import org.openjdk.jmh.annotations.Mode;29import org.openjdk.jmh.annotations.OutputTimeUnit;30import org.openjdk.jmh.annotations.Param;31import org.openjdk.jmh.annotations.Scope;32import org.openjdk.jmh.annotations.Setup;33import org.openjdk.jmh.annotations.State;3435import java.util.concurrent.TimeUnit;36import java.util.Arrays;3738@State(Scope.Benchmark)39@BenchmarkMode(Mode.AverageTime)40@OutputTimeUnit(TimeUnit.NANOSECONDS)41public class ArrayFill {42@Param("65536") private int size;4344private byte[] ba;45private short[] sa;46private int[] ia;4748@Setup49public void setup() {50ba = new byte[size];51sa = new short[size];52ia = new int[size];53}5455@Benchmark56public void fillByteArray() {57for (int i = 0; i < size; i++) {58ba[i] = (byte) 123;59}60}6162@Benchmark63public void fillShortArray() {64for (int i = 0; i < size; i++) {65sa[i] = (short) 12345;66}67}6869@Benchmark70public void fillIntArray() {71for (int i = 0; i < size; i++) {72ia[i] = 1234567890;73}74}7576@Benchmark77public void zeroByteArray() {78for (int i = 0; i < size; i++) {79ba[i] = 0;80}81}8283@Benchmark84public void zeroShortArray() {85for (int i = 0; i < size; i++) {86sa[i] = 0;87}88}8990@Benchmark91public void zeroIntArray() {92for (int i = 0; i < size; i++) {93ia[i] = 0;94}95}96}979899100