1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs.perf;
18
19 import org.apache.commons.vfs.FileName;
20 import org.apache.commons.vfs.FileObject;
21 import org.apache.commons.vfs.FileSystemException;
22 import org.apache.commons.vfs.FileSystemManager;
23 import org.apache.commons.vfs.VFS;
24
25 public class FileNamePerformance
26 {
27 private final static int NUOF_RESOLVES = 100000;
28
29 public static void main(String[] args) throws FileSystemException
30 {
31 FileSystemManager mgr = VFS.getManager();
32
33 FileObject root = mgr
34 .resolveFile("smb://HOME//vfsusr:vfs%2f%25//te:st@10.0.1.54/vfsusr");
35 FileName rootName = root.getName();
36
37 testNames(mgr, rootName);
38
39 testChildren(root);
40
41 testFiles(mgr);
42 }
43
44 private static void testFiles(FileSystemManager mgr) throws FileSystemException
45 {
46 for (int i = 0; i < 10; i++)
47 {
48
49 mgr.resolveFile("smb://HOME//vfsusr:vfs%2f%25//te:st@10.0.1.54/vfsusr/many/path/elements/with%25esc/any%25where/to/file.txt");
50 }
51
52 long start = System.currentTimeMillis();
53 for (int i = 0; i < NUOF_RESOLVES; i++)
54 {
55 mgr.resolveFile("smb://HOME//vfsusr:vfs%2f%25//te:st@10.0.1.54/vfsusr/many/path/elements/with%25esc/any%25where/to/file.txt");
56 }
57 long end = System.currentTimeMillis();
58
59 System.err.println("time to resolve " + NUOF_RESOLVES + " files: "
60 + (end - start) + "ms");
61 }
62
63 private static void testChildren(FileObject root) throws FileSystemException
64 {
65 for (int i = 0; i < 10; i++)
66 {
67
68 root.resolveFile("/many/path/elements/with%25esc/any%25where/to/file.txt");
69 }
70
71 long start = System.currentTimeMillis();
72 for (int i = 0; i < NUOF_RESOLVES; i++)
73 {
74 root.resolveFile("/many/path/elements/with%25esc/any%25where/to/file.txt");
75 }
76 long end = System.currentTimeMillis();
77
78 System.err.println("time to resolve " + NUOF_RESOLVES + " childs: "
79 + (end - start) + "ms");
80 }
81
82 private static void testNames(FileSystemManager mgr, FileName rootName) throws FileSystemException
83 {
84 for (int i = 0; i < 10; i++)
85 {
86
87 mgr.resolveName(rootName,
88 "/many/path/elements/with%25esc/any%25where/to/file.txt");
89 }
90
91 long start = System.currentTimeMillis();
92 for (int i = 0; i < NUOF_RESOLVES; i++)
93 {
94 mgr.resolveName(rootName,
95 "/many/path/elements/with%25esc/any%25where/to/file.txt");
96 }
97 long end = System.currentTimeMillis();
98
99 System.err.println("time to resolve " + NUOF_RESOLVES + " names: "
100 + (end - start) + "ms");
101 }
102 }