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