Path: blob/master/test/micro/org/openjdk/bench/vm/compiler/LoopUnroll.java
66646 views
/*1* Copyright (C) 2021 THL A29 Limited, a Tencent company. 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*/2223package org.openjdk.bench.vm.compiler;2425import org.openjdk.jmh.annotations.*;26import org.openjdk.jmh.infra.*;27import java.util.concurrent.TimeUnit;2829@Warmup(iterations = 3, time = 5, timeUnit = TimeUnit.SECONDS)30@Measurement(iterations = 4, time = 5, timeUnit = TimeUnit.SECONDS)31@BenchmarkMode(Mode.Throughput)32@OutputTimeUnit(TimeUnit.SECONDS)33@State(Scope.Thread)34@Fork(value=1)35public class LoopUnroll {36@Param({"16", "32", "64", "128", "256", "512", "1024"})37private int VECLEN;3839private byte[][] a;40private byte[][] b;41private byte[][] c;4243@Setup44public void init() {45a = new byte[VECLEN][VECLEN];46b = new byte[VECLEN][VECLEN];47c = new byte[VECLEN][VECLEN];48}4950@CompilerControl(CompilerControl.Mode.DONT_INLINE)51private int run_workload1(int count, byte[][] a , byte[][] b, byte[][] c) {52for(int i = 0; i < a.length; i++) {53for (int j = 0; j < a[0].length; j++) {54a[i][j] = (byte)(b[i][j] + c[i][j]);55}56}57return a[count][count];58}5960@Benchmark61public void workload1_caller(Blackhole bh) {62int r = 0;63for(int i = 0 ; i < 100; i++) {64r += run_workload1(i % a.length, a, b, c);65}66bh.consume(r);67}6869@CompilerControl(CompilerControl.Mode.DONT_INLINE)70private int run_workload2(int count, byte[][] a , byte[][] b) {71for(int i = 0; i < b.length; i++) {72for (int j = 0; j < b[0].length; j++) {73a[i][j] = b[i][j];74}75}76return a[count][count];77}7879@Benchmark80public void workload2_caller(Blackhole bh) {81int r = 0;82for(int i = 0 ; i < 100; i++) {83r += run_workload2(i % a.length, a, b);84}85bh.consume(r);86}87}888990