Path: blob/master/test/micro/org/openjdk/bench/java/util/ArraysMismatchPartialInlining.java
66646 views
/*1* Copyright (c) 2021, 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*/22package org.openjdk.bench.java.util;2324import java.util.Arrays;25import java.util.concurrent.TimeUnit;26import org.openjdk.jmh.annotations.Benchmark;27import org.openjdk.jmh.annotations.BenchmarkMode;28import org.openjdk.jmh.annotations.Measurement;29import org.openjdk.jmh.annotations.Mode;30import org.openjdk.jmh.annotations.OutputTimeUnit;31import org.openjdk.jmh.annotations.Param;32import org.openjdk.jmh.annotations.Scope;33import org.openjdk.jmh.annotations.Setup;34import org.openjdk.jmh.annotations.State;35import org.openjdk.jmh.annotations.Warmup;3637@BenchmarkMode(Mode.Throughput)38@OutputTimeUnit(TimeUnit.MILLISECONDS)39@State(Scope.Thread)40public class ArraysMismatchPartialInlining {4142@Param({"3", "4", "5", "6", "7", "15", "31", "63", "95", "800"})43private static int size;4445byte [] barray1;46char [] carray1;47short [] sarray1;48int [] iarray1;49long [] larray1;50float [] farray1;51double [] darray1;5253byte [] barray2;54char [] carray2;55short [] sarray2;56int [] iarray2;57long [] larray2;58float [] farray2;59double [] darray2;6061@Setup62public void setup() {63barray1 = new byte[size];64carray1 = new char[size];65sarray1 = new short[size];66iarray1 = new int[size];67larray1 = new long[size];68farray1 = new float[size];69darray1 = new double[size];7071barray2 = new byte[size];72carray2 = new char[size];73sarray2 = new short[size];74iarray2 = new int[size];75larray2 = new long[size];76farray2 = new float[size];77darray2 = new double[size];7879Arrays.fill(barray1 , (byte)0xF);80Arrays.fill(carray1 , (char)0xFF);81Arrays.fill(sarray1 , (short)0xFF);82Arrays.fill(iarray1 , -1);83Arrays.fill(larray1 , -1L);84Arrays.fill(farray1 , -1.0f);85Arrays.fill(darray1, -1.0);8687Arrays.fill(barray2 , (byte)0xF);88Arrays.fill(carray2 , (char)0xFF);89Arrays.fill(sarray2 , (short)0xFF);90Arrays.fill(iarray2 , -1);91Arrays.fill(larray2 , -1L);92Arrays.fill(farray2 , -1.0F);93Arrays.fill(darray2, -1.0);9495barray2[size-1] = (byte)1;96carray2[size-1] = (char)1;97sarray2[size-1] = (short)1;98iarray2[size-1] = 1;99larray2[size-1] = 1L;100farray2[size-1] = 1.0f;101darray2[size-1] = 1.0;102}103104@Benchmark105public int testByteMatch() {106return Arrays.mismatch(barray1, barray2);107}108109@Benchmark110public int testCharMatch() {111return Arrays.mismatch(carray1, carray2);112}113114@Benchmark115public int testShortMatch() {116return Arrays.mismatch(sarray1, sarray2);117}118119@Benchmark120public int testIntMatch() {121return Arrays.mismatch(iarray1, iarray2);122}123124@Benchmark125public int testLongMatch() {126return Arrays.mismatch(larray1, larray2);127}128129@Benchmark130public int testFloatMatch() {131return Arrays.mismatch(farray1, farray2);132}133134@Benchmark135public int testDoubleMatch() {136return Arrays.mismatch(darray1, darray2);137}138}139140141