1 /* 2 * Copyright (c) 2014 Oracle and/or its affiliates. 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 it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package org.openjdk.bench.java.util; 26 27 import org.openjdk.jmh.annotations.Benchmark; 28 import org.openjdk.jmh.annotations.BenchmarkMode; 29 import org.openjdk.jmh.annotations.Mode; 30 import org.openjdk.jmh.annotations.OutputTimeUnit; 31 import org.openjdk.jmh.annotations.Scope; 32 import org.openjdk.jmh.annotations.State; 33 34 import java.util.Arrays; 35 import java.util.concurrent.TimeUnit; 36 37 /** 38 * Tests for Array.equals() with 80 entry arrays differing at beginning, middle, or end. 39 */ 40 @BenchmarkMode(Mode.AverageTime) 41 @OutputTimeUnit(TimeUnit.NANOSECONDS) 42 @State(Scope.Thread) 43 public class ArraysEquals { 44 45 public char[] testCharArray1 = "1234567890123456789012345678901234567890123456789012345678901234567890123456789a".toCharArray(); 46 public char[] testCharArray2 = "1234567890123456789012345678901234567890123456789012345678901234567890123456789b".toCharArray(); 47 public char[] testCharArray3 = "123456789012345678901234567890123456789a123456789012345678901234567890123456789b".toCharArray(); 48 public char[] testCharArray4 = "1234567890a2345678901234567890123456789a123456789012345678901234567890123456789b".toCharArray(); 49 public char[] testCharArray5 = "1234567890123456789012345678901234567890123456789012345678901234567890123456789a".toCharArray(); 50 public byte[] testByteArray1 = "1234567890123456789012345678901234567890123456789012345678901234567890123456789a".getBytes(); 51 public byte[] testByteArray2 = "1234567890123456789012345678901234567890123456789012345678901234567890123456789b".getBytes(); 52 public byte[] testByteArray3 = "123456789012345678901234567890123456789a123456789012345678901234567890123456789b".getBytes(); 53 public byte[] testByteArray4 = "1234567890a2345678901234567890123456789a123456789012345678901234567890123456789b".getBytes(); 54 public byte[] testByteArray5 = "1234567890123456789012345678901234567890123456789012345678901234567890123456789a".getBytes(); 55 56 /** Char array tests */ 57 58 @Benchmark 59 public boolean testCharTrue() { 60 return Arrays.equals(testCharArray1, testCharArray5); 61 } 62 63 @Benchmark 64 public boolean testCharFalseEnd() { 65 return Arrays.equals(testCharArray1, testCharArray2); 66 } 67 68 @Benchmark 69 public boolean testCharFalseMid() { 70 return Arrays.equals(testCharArray1, testCharArray3); 71 } 72 73 @Benchmark 74 public boolean testCharFalseBeginning() { 75 return Arrays.equals(testCharArray1, testCharArray4); 76 } 77 78 /** Byte arrays tests */ 79 @Benchmark 80 public boolean testByteTrue() { 81 return Arrays.equals(testByteArray1, testByteArray5); 82 } 83 84 @Benchmark 85 public boolean testByteFalseEnd() { 86 return Arrays.equals(testByteArray1, testByteArray2); 87 } 88 89 @Benchmark 90 public boolean testByteFalseMid() { 91 return Arrays.equals(testByteArray1, testByteArray3); 92 } 93 94 @Benchmark 95 public boolean testByteFalseBeginning() { 96 return Arrays.equals(testByteArray1, testByteArray4); 97 } 98 }