Path: blob/master/test/micro/org/openjdk/bench/java/lang/RotateBenchmark.java
41161 views
//1// Copyright (c) 2003, 2020, 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//22//23package org.openjdk.bench.java.lang;2425import java.util.Random;26import java.util.concurrent.TimeUnit;27import org.openjdk.jmh.annotations.*;28import org.openjdk.jmh.infra.Blackhole;2930@OutputTimeUnit(TimeUnit.MILLISECONDS)31@State(Scope.Thread)32@BenchmarkMode(Mode.Throughput)33public class RotateBenchmark {3435@Param({"1024"})36public int TESTSIZE;3738@Param({"20"})39public int SHIFT;4041public long [] larr;42public int [] iarr;4344public long [] lres;45public int [] ires;464748@Setup(Level.Trial)49public void BmSetup() {50Random r = new Random(1024);51larr = new long[TESTSIZE];52iarr = new int[TESTSIZE];53lres = new long[TESTSIZE];54ires = new int[TESTSIZE];5556for (int i = 0; i < TESTSIZE; i++) {57larr[i] = r.nextLong();58}5960for (int i = 0; i < TESTSIZE; i++) {61iarr[i] = r.nextInt();62}63}6465@Benchmark66public void testRotateLeftI() {67for (int i = 0; i < TESTSIZE; i++)68ires[i] = Integer.rotateLeft(iarr[i], SHIFT);69}70@Benchmark71public void testRotateRightI() {72for (int i = 0; i < TESTSIZE; i++)73ires[i] = Integer.rotateRight(iarr[i], SHIFT);74}75@Benchmark76public void testRotateLeftL() {77for (int i = 0; i < TESTSIZE; i++)78lres[i] = Long.rotateLeft(larr[i], SHIFT);79}80@Benchmark81public void testRotateRightL() {82for (int i = 0; i < TESTSIZE; i++)83lres[i] = Long.rotateRight(larr[i], SHIFT);84}8586}878889