Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/micro/org/openjdk/bench/java/lang/RotateBenchmark.java
41161 views
1
//
2
// Copyright (c) 2003, 2020, 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
//
24
package org.openjdk.bench.java.lang;
25
26
import java.util.Random;
27
import java.util.concurrent.TimeUnit;
28
import org.openjdk.jmh.annotations.*;
29
import org.openjdk.jmh.infra.Blackhole;
30
31
@OutputTimeUnit(TimeUnit.MILLISECONDS)
32
@State(Scope.Thread)
33
@BenchmarkMode(Mode.Throughput)
34
public class RotateBenchmark {
35
36
@Param({"1024"})
37
public int TESTSIZE;
38
39
@Param({"20"})
40
public int SHIFT;
41
42
public long [] larr;
43
public int [] iarr;
44
45
public long [] lres;
46
public int [] ires;
47
48
49
@Setup(Level.Trial)
50
public void BmSetup() {
51
Random r = new Random(1024);
52
larr = new long[TESTSIZE];
53
iarr = new int[TESTSIZE];
54
lres = new long[TESTSIZE];
55
ires = new int[TESTSIZE];
56
57
for (int i = 0; i < TESTSIZE; i++) {
58
larr[i] = r.nextLong();
59
}
60
61
for (int i = 0; i < TESTSIZE; i++) {
62
iarr[i] = r.nextInt();
63
}
64
}
65
66
@Benchmark
67
public void testRotateLeftI() {
68
for (int i = 0; i < TESTSIZE; i++)
69
ires[i] = Integer.rotateLeft(iarr[i], SHIFT);
70
}
71
@Benchmark
72
public void testRotateRightI() {
73
for (int i = 0; i < TESTSIZE; i++)
74
ires[i] = Integer.rotateRight(iarr[i], SHIFT);
75
}
76
@Benchmark
77
public void testRotateLeftL() {
78
for (int i = 0; i < TESTSIZE; i++)
79
lres[i] = Long.rotateLeft(larr[i], SHIFT);
80
}
81
@Benchmark
82
public void testRotateRightL() {
83
for (int i = 0; i < TESTSIZE; i++)
84
lres[i] = Long.rotateRight(larr[i], SHIFT);
85
}
86
87
}
88
89