Path: blob/master/test/micro/org/openjdk/bench/java/lang/ArrayCopyObject.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;34import org.openjdk.jmh.results.Result;35import org.openjdk.jmh.results.RunResult;36import org.openjdk.jmh.runner.Runner;37import org.openjdk.jmh.runner.RunnerException;38import org.openjdk.jmh.runner.options.Options;39import org.openjdk.jmh.runner.options.OptionsBuilder;40import org.openjdk.jmh.runner.options.TimeValue;4142434445import java.util.concurrent.TimeUnit;46import java.util.Arrays;4748class MyClass {49public int field1;50public int field2;51public int field3;5253public MyClass(int val) {54field1 = val;55field2 = val;56field3 = val;57}58}5960@State(Scope.Benchmark)61@BenchmarkMode(Mode.Throughput)62@OutputTimeUnit(TimeUnit.MILLISECONDS)63public class ArrayCopyObject {64@Param({"31", "63", "127" , "2047" , "4095", "8191"}) private int size;6566private MyClass [] src;67private MyClass [] dst;6869@Setup70public void setup() {71src = new MyClass[size];72dst = new MyClass[size];73for (int i = 0; i < src.length ; i++) {74src[i] = new MyClass(i);75dst[i] = new MyClass(0);76}77}7879@Benchmark80public void disjoint_micro() {81System.arraycopy(src, 0 , dst, 0 , size);82}8384@Benchmark85public void conjoint_micro() {86System.arraycopy(src, 0 , src, 10 , size - 10 );87}8889public static void main(String[] args) throws RunnerException {90String [] base_opts =91{ "-XX:+UnlockDiagnosticVMOptions ",92"-XX:+IgnoreUnrecognizedVMOptions ",93"-XX:UseAVX=3" };94String [] opts_str1 = {"-XX:-UseCompressedOops "};95String [] opts_str2 = {"-XX:+UseCompressedOops "};9697Options baseOpts = new OptionsBuilder()98.include(ArrayCopyObject.class.getName())99.warmupTime(TimeValue.seconds(30))100.measurementTime(TimeValue.seconds(10))101.warmupIterations(1)102.measurementIterations(2)103.jvmArgs(base_opts)104.forks(1)105.build();106107RunResult r1 = new Runner(new OptionsBuilder()108.parent(baseOpts)109.jvmArgs(opts_str1)110.build()).runSingle();111112RunResult r2 = new Runner(new OptionsBuilder()113.parent(baseOpts)114.jvmArgs(opts_str2)115.build()).runSingle();116117System.out.println(r1.getPrimaryResult().getScore() + r2.getPrimaryResult().getScore());118}119}120121122123