JU7WuKslKle9UaAL3r21M changeset

Changeset653337376466 (b)
ParentNone (a)
ab
0+package zip.simple;
0+
0+import com.jcraft.jzlib.ZStream;
0+import java.io.FileInputStream;
0+import java.util.ArrayList;
0+import java.util.Enumeration;
0+import java.util.List;
0+import java.util.concurrent.TimeUnit;
0+import java.util.jar.JarEntry;
0+import java.util.jar.JarInputStream;
0+import java.util.zip.ZipEntry;
0+import java.util.zip.ZipFile;
0+
0+/**
0+ * @author Romain Manni-Bucau
0+ */
0+public class Main {
0+    public static void main(String[] a) {
0+        final String filename = "/home/rmannibucau/Bureau/openejb-core-3.1.4.jar";
0+        final int nTimes = 100;
0+
0+        long start = 0, end = 0;
0+        List<String> list = new ArrayList<String>();
0+
0+        // jdk way: jar
0+        for (int i = 0; i < nTimes; i++) {
0+            list.clear();
0+
0+            try {
0+                JarInputStream jarFile = new JarInputStream(new FileInputStream(filename));
0+                JarEntry jarEntry;
0+
0+                start = System.nanoTime();
0+                while ((jarEntry = jarFile.getNextJarEntry()) != null) {
0+                    if (jarEntry.getName().endsWith(".class")) {
0+                        list.add(jarEntry.getName().replaceAll("/", "\\."));
0+                    }
0+                }
0+                end = System.nanoTime();
0+            } catch (Exception e) {
0+                e.printStackTrace();
0+            }
0+        }
0+        System.out.println(TimeUnit.NANOSECONDS.toMillis(end - start) + " for " + list.size() + " classes ");
0+
0+        // jdk way: zip
0+        for (int i = 0; i < nTimes; i++) {
0+            list.clear();
0+
0+            try {
0+                ZipFile zipFile = new ZipFile(filename);
0+                Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
0+
0+                start = System.nanoTime();
0+                while (zipEntries.hasMoreElements()) {
0+                    ZipEntry entry = zipEntries.nextElement();
0+                    if (entry.getName().endsWith(".class")) {
0+                        list.add(entry.getName().replaceAll("/", "\\."));
0+                    }
0+                }
0+                end = System.nanoTime();
0+            } catch (Exception e) {
0+                e.printStackTrace();
0+            }
0+        }
0+        System.out.println(TimeUnit.NANOSECONDS.toMillis(end - start) + " for " + list.size() + " classes ");
0+    }
0+}
...
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
69
70
71
--- Revision None
+++ Revision 653337376466
@@ -0,0 +1,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 ");
+ }
+}