Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/micro/org/openjdk/bench/java/util/ZipFind.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.Setup;
31
import org.openjdk.jmh.annotations.State;
32
import org.openjdk.jmh.annotations.TearDown;
33
import org.openjdk.jmh.infra.Blackhole;
34
35
import java.io.IOException;
36
import java.net.URISyntaxException;
37
import java.util.concurrent.TimeUnit;
38
import java.util.zip.ZipEntry;
39
import java.util.zip.ZipFile;
40
41
/**
42
* Tests ZipFile.getEntry() on the microbenchmarks.jar zip file
43
*/
44
@BenchmarkMode(Mode.AverageTime)
45
@OutputTimeUnit(TimeUnit.NANOSECONDS)
46
@State(Scope.Thread)
47
public class ZipFind {
48
49
// Files that exist in the microbenchmarks.jar zip file
50
public static final String[] existingFiles = {"org/openjdk/bench/java/util/ZipFind.class",
51
"org/openjdk/bench/vm/lang/Throw.class",
52
"org/openjdk/bench/java/nio/ByteBuffers.class"};
53
public static String[] nonExistingFiles = {"/try/to/findme.not", "needle/in/a/HayStack.class"};
54
55
private ZipFile zip;
56
57
@Setup
58
public void prepare() throws IOException, URISyntaxException {
59
String zipFile = this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
60
zip = new ZipFile(zipFile);
61
62
// Verify no typos in the filename lists above
63
assert zip.getEntry(ZipFind.nonExistingFiles[0]) == null;
64
assert zip.getEntry(ZipFind.existingFiles[0]) != null;
65
assert zip.getEntry(ZipFind.existingFiles[1]) != null;
66
assert zip.getEntry(ZipFind.existingFiles[2]) != null;
67
}
68
69
@TearDown
70
public void cleanup() throws IOException {
71
zip.close();
72
}
73
74
@Benchmark
75
public ZipEntry testOneNonExisting() throws IOException {
76
return zip.getEntry(ZipFind.nonExistingFiles[0]);
77
}
78
79
@Benchmark
80
public void testTwoNonExisting(Blackhole bh) throws IOException {
81
bh.consume(zip.getEntry(nonExistingFiles[0]));
82
bh.consume(zip.getEntry(nonExistingFiles[1]));
83
}
84
85
@Benchmark
86
public void testNonExistingAndExisting(Blackhole bh) throws IOException {
87
bh.consume(zip.getEntry(nonExistingFiles[0]));
88
bh.consume(zip.getEntry(existingFiles[0]));
89
}
90
91
@Benchmark
92
public ZipEntry testOneExisting() throws IOException {
93
return zip.getEntry(ZipFind.existingFiles[0]);
94
}
95
96
@Benchmark
97
public void testTwoExisting(Blackhole bh) throws IOException {
98
bh.consume(zip.getEntry(existingFiles[0]));
99
bh.consume(zip.getEntry(existingFiles[1]));
100
}
101
102
@Benchmark
103
public void testThreeExisting(Blackhole bh) throws IOException {
104
bh.consume(zip.getEntry(existingFiles[0]));
105
bh.consume(zip.getEntry(existingFiles[1]));
106
bh.consume(zip.getEntry(existingFiles[2]));
107
}
108
}
109
110