Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/micro/org/openjdk/bench/vm/compiler/SkipIntToLongCast.java
41161 views
1
/*
2
* Copyright (c) BELLSOFT. 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
24
package org.openjdk.bench.vm.compiler;
25
26
import org.openjdk.jmh.annotations.Benchmark;
27
import org.openjdk.jmh.annotations.BenchmarkMode;
28
import org.openjdk.jmh.annotations.Fork;
29
import org.openjdk.jmh.annotations.Measurement;
30
import org.openjdk.jmh.annotations.Mode;
31
import org.openjdk.jmh.annotations.OutputTimeUnit;
32
import org.openjdk.jmh.annotations.Scope;
33
import org.openjdk.jmh.annotations.Setup;
34
import org.openjdk.jmh.annotations.State;
35
import org.openjdk.jmh.annotations.Warmup;
36
37
import java.util.concurrent.TimeUnit;
38
39
@BenchmarkMode(Mode.AverageTime)
40
@OutputTimeUnit(TimeUnit.NANOSECONDS)
41
@State(Scope.Thread)
42
@Warmup(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
43
@Measurement(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
44
@Fork(3)
45
public class SkipIntToLongCast {
46
47
private static final long ARRAYSIZE_L = 40L;
48
49
public int[] intValues;
50
public int intValue;
51
52
@Setup
53
public void setup() {
54
int size = (int)ARRAYSIZE_L;
55
intValues = new int[size];
56
for (int i = 0; i < size; i++) {
57
intValues[i] = i + 1;
58
}
59
}
60
61
@Benchmark
62
public int skipCastTestRight() {
63
for (int i = 0; i < ARRAYSIZE_L; i++) {
64
if (intValues[i] == ARRAYSIZE_L) {
65
return i;
66
}
67
}
68
return 0;
69
}
70
71
@Benchmark
72
public int skipCastTestLeft() {
73
for (int i = 0; i < ARRAYSIZE_L; i++) {
74
if (ARRAYSIZE_L == intValues[i]) {
75
return i;
76
}
77
}
78
return 0;
79
}
80
81
@Benchmark
82
public long skipMaskedSmallPositiveCast() {
83
int value = intValue;
84
return (long)(value & 0x1) ^ (long)(value & 0x3) ^ (long)(value & 0x7) ^ (long)(value & 0xF) ^
85
(long)(value & 0x1F) ^ (long)(value & 0x3F) ^ (long)(value & 0x7F) ^ (long)(value & 0xFF) ^
86
(long)(value & 0x1FF) ^ (long)(value & 0x3FF) ^ (long)(value & 0x7FF) ^ (long)(value & 0xFFF) ^
87
(long)(value & 0x1FFF) ^ (long)(value & 0x3FFF) ^ (long)(value & 0x7FFF) ^ (long)(value & 0xFFFF);
88
}
89
}
90
91