Path: blob/master/test/micro/org/openjdk/bench/java/lang/ArrayCopyUnalignedBoth.java
41161 views
/*1* Copyright (c) 2014, 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.lang;2324import org.openjdk.jmh.annotations.Benchmark;25import org.openjdk.jmh.annotations.BenchmarkMode;26import org.openjdk.jmh.annotations.Mode;27import org.openjdk.jmh.annotations.OutputTimeUnit;28import org.openjdk.jmh.annotations.Param;29import org.openjdk.jmh.annotations.Scope;30import org.openjdk.jmh.annotations.Setup;31import org.openjdk.jmh.annotations.State;3233import java.util.concurrent.TimeUnit;3435/**36* Benchmark measuring Unaligned System.arraycopy.37*/38@BenchmarkMode(Mode.AverageTime)39@OutputTimeUnit(TimeUnit.NANOSECONDS)40@State(Scope.Thread)41public class ArrayCopyUnalignedBoth {4243@Param({"1", "3", "5", "10", "20", "70", "150", "300", "600", "1200"})44int length;4546int fromPos, toPos;47byte[] fromByteArr, toByteArr;48char[] fromCharArr, toCharArr;49int[] fromIntArr, toIntArr;50long[] fromLongArr, toLongArr;5152@Setup53public void setup() {54// Both positions Unaligned55fromPos = 9;56toPos = 10;5758fromByteArr = new byte[1210];59toByteArr = new byte[1210];60fromCharArr = new char[1210];61toCharArr = new char[1210];62fromIntArr = new int[1210];63toIntArr = new int[1210];64fromLongArr = new long[1210];65toLongArr = new long[1210];66}6768@Benchmark69public void testByte() {70System.arraycopy(fromByteArr, fromPos, toByteArr, toPos, length);71}7273@Benchmark74public void testChar() {75System.arraycopy(fromCharArr, fromPos, toCharArr, toPos, length);76}7778@Benchmark79public void testInt() {80System.arraycopy(fromIntArr, fromPos, toIntArr, toPos, length);81}8283@Benchmark84public void testLong() {85System.arraycopy(fromLongArr, fromPos, toLongArr, toPos, length);86}87}888990