Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/micro/org/openjdk/bench/java/util/ArraysEquals.java
41161 views
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.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 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 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
package org.openjdk.bench.java.util;
24
25
import org.openjdk.jmh.annotations.Benchmark;
26
import org.openjdk.jmh.annotations.BenchmarkMode;
27
import org.openjdk.jmh.annotations.Mode;
28
import org.openjdk.jmh.annotations.OutputTimeUnit;
29
import org.openjdk.jmh.annotations.Scope;
30
import org.openjdk.jmh.annotations.State;
31
32
import java.util.Arrays;
33
import java.util.concurrent.TimeUnit;
34
35
/**
36
* Tests for Array.equals() with 80 entry arrays differing at beginning, middle, or end.
37
*/
38
@BenchmarkMode(Mode.AverageTime)
39
@OutputTimeUnit(TimeUnit.NANOSECONDS)
40
@State(Scope.Thread)
41
public class ArraysEquals {
42
43
public char[] testCharArray1 = "1234567890123456789012345678901234567890123456789012345678901234567890123456789a".toCharArray();
44
public char[] testCharArray2 = "1234567890123456789012345678901234567890123456789012345678901234567890123456789b".toCharArray();
45
public char[] testCharArray3 = "123456789012345678901234567890123456789a123456789012345678901234567890123456789b".toCharArray();
46
public char[] testCharArray4 = "1234567890a2345678901234567890123456789a123456789012345678901234567890123456789b".toCharArray();
47
public char[] testCharArray5 = "1234567890123456789012345678901234567890123456789012345678901234567890123456789a".toCharArray();
48
public byte[] testByteArray1 = "1234567890123456789012345678901234567890123456789012345678901234567890123456789a".getBytes();
49
public byte[] testByteArray2 = "1234567890123456789012345678901234567890123456789012345678901234567890123456789b".getBytes();
50
public byte[] testByteArray3 = "123456789012345678901234567890123456789a123456789012345678901234567890123456789b".getBytes();
51
public byte[] testByteArray4 = "1234567890a2345678901234567890123456789a123456789012345678901234567890123456789b".getBytes();
52
public byte[] testByteArray5 = "1234567890123456789012345678901234567890123456789012345678901234567890123456789a".getBytes();
53
54
/** Char array tests */
55
56
@Benchmark
57
public boolean testCharTrue() {
58
return Arrays.equals(testCharArray1, testCharArray5);
59
}
60
61
@Benchmark
62
public boolean testCharFalseEnd() {
63
return Arrays.equals(testCharArray1, testCharArray2);
64
}
65
66
@Benchmark
67
public boolean testCharFalseMid() {
68
return Arrays.equals(testCharArray1, testCharArray3);
69
}
70
71
@Benchmark
72
public boolean testCharFalseBeginning() {
73
return Arrays.equals(testCharArray1, testCharArray4);
74
}
75
76
/** Byte arrays tests */
77
@Benchmark
78
public boolean testByteTrue() {
79
return Arrays.equals(testByteArray1, testByteArray5);
80
}
81
82
@Benchmark
83
public boolean testByteFalseEnd() {
84
return Arrays.equals(testByteArray1, testByteArray2);
85
}
86
87
@Benchmark
88
public boolean testByteFalseMid() {
89
return Arrays.equals(testByteArray1, testByteArray3);
90
}
91
92
@Benchmark
93
public boolean testByteFalseBeginning() {
94
return Arrays.equals(testByteArray1, testByteArray4);
95
}
96
}
97
98