View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.vfs2.perf;
18  
19  import org.apache.commons.vfs2.FileName;
20  import org.apache.commons.vfs2.FileObject;
21  import org.apache.commons.vfs2.FileSystemException;
22  import org.apache.commons.vfs2.FileSystemManager;
23  import org.apache.commons.vfs2.VFS;
24  
25  public class FileNamePerformance {
26  
27      private final static int NUOF_RESOLVES = 100000;
28  
29      public static void main(final String[] args) throws FileSystemException {
30          final FileSystemManager mgr = VFS.getManager();
31  
32          final FileObject root = mgr.resolveFile("smb://HOME\\vfsusr:vfs%2f%25\\te:st@10.0.1.54/vfsusr");
33          final FileName rootName = root.getName();
34  
35          testNames(mgr, rootName);
36  
37          testChildren(root);
38  
39          testFiles(mgr);
40      }
41  
42      private static void testChildren(final FileObject root) throws FileSystemException {
43          for (int i = 0; i < 10; i++) {
44              // warmup jvm
45              root.resolveFile("/many/path/elements/with%25esc/any%25where/to/file.txt");
46          }
47  
48          final long startMillis = System.currentTimeMillis();
49          for (int i = 0; i < NUOF_RESOLVES; i++) {
50              root.resolveFile("/many/path/elements/with%25esc/any%25where/to/file.txt");
51          }
52          final long endMillis = System.currentTimeMillis();
53  
54          System.err.println("time to resolve " + NUOF_RESOLVES + " children: " + (endMillis - startMillis) + " milliseconds");
55      }
56  
57      private static void testFiles(final FileSystemManager mgr) throws FileSystemException {
58          for (int i = 0; i < 10; i++) {
59              // warmup jvm
60              mgr.resolveFile(
61                      "smb://HOME\\vfsusr:vfs%2f%25\\te:st@10.0.1.54/vfsusr/many/path/elements/with%25esc/any%25where/to/file.txt");
62          }
63  
64          final long startMillis = System.currentTimeMillis();
65          for (int i = 0; i < NUOF_RESOLVES; i++) {
66              mgr.resolveFile(
67                      "smb://HOME\\vfsusr:vfs%2f%25\\te:st@10.0.1.54/vfsusr/many/path/elements/with%25esc/any%25where/to/file.txt");
68          }
69          final long endMillis = System.currentTimeMillis();
70  
71          System.err.println("time to resolve " + NUOF_RESOLVES + " files: " + (endMillis - startMillis) + " milliseconds");
72      }
73  
74      private static void testNames(final FileSystemManager mgr, final FileName rootName) throws FileSystemException {
75          for (int i = 0; i < 10; i++) {
76              // warmup jvm
77              mgr.resolveName(rootName, "/many/path/elements/with%25esc/any%25where/to/file.txt");
78          }
79  
80          final long startMillis = System.currentTimeMillis();
81          for (int i = 0; i < NUOF_RESOLVES; i++) {
82              mgr.resolveName(rootName, "/many/path/elements/with%25esc/any%25where/to/file.txt");
83          }
84          final long endMillis = System.currentTimeMillis();
85  
86          System.err.println("time to resolve " + NUOF_RESOLVES + " names: " + (endMillis - startMillis) + " milliseconds");
87      }
88  
89  }