Revision 653337376466 () - Diff

Link to this snippet: https://friendpaste.com/JU7WuKslKle9UaAL3r21M
Embed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package zip.simple;

import com.jcraft.jzlib.ZStream;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

/**
* @author Romain Manni-Bucau
*/
public class Main {
public static void main(String[] a) {
final String filename = "/home/rmannibucau/Bureau/openejb-core-3.1.4.jar";
final int nTimes = 100;

long start = 0, end = 0;
List<String> list = new ArrayList<String>();

// jdk way: jar
for (int i = 0; i < nTimes; i++) {
list.clear();

try {
JarInputStream jarFile = new JarInputStream(new FileInputStream(filename));
JarEntry jarEntry;

start = System.nanoTime();
while ((jarEntry = jarFile.getNextJarEntry()) != null) {
if (jarEntry.getName().endsWith(".class")) {
list.add(jarEntry.getName().replaceAll("/", "\\."));
}
}
end = System.nanoTime();
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println(TimeUnit.NANOSECONDS.toMillis(end - start) + " for " + list.size() + " classes ");

// jdk way: zip
for (int i = 0; i < nTimes; i++) {
list.clear();

try {
ZipFile zipFile = new ZipFile(filename);
Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();

start = System.nanoTime();
while (zipEntries.hasMoreElements()) {
ZipEntry entry = zipEntries.nextElement();
if (entry.getName().endsWith(".class")) {
list.add(entry.getName().replaceAll("/", "\\."));
}
}
end = System.nanoTime();
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println(TimeUnit.NANOSECONDS.toMillis(end - start) + " for " + list.size() + " classes ");
}
}