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      private final static int NUOF_RESOLVES = 100000;
27  
28      public static void main(final String[] args) throws FileSystemException {
29          final FileSystemManager mgr = VFS.getManager();
30  
31          final FileObject root = mgr.resolveFile("smb://HOME\\vfsusr:vfs%2f%25\\te:st@10.0.1.54/vfsusr");
32          final FileName rootName = root.getName();
33  
34          testNames(mgr, rootName);
35  
36          testChildren(root);
37  
38          testFiles(mgr);
39      }
40  
41      private static void testChildren(final FileObject root) throws FileSystemException {
42          for (int i = 0; i < 10; i++) {
43              // warmup jvm
44              root.resolveFile("/many/path/elements/with%25esc/any%25where/to/file.txt");
45          }
46  
47          final long startMillis = System.currentTimeMillis();
48          for (int i = 0; i < NUOF_RESOLVES; i++) {
49              root.resolveFile("/many/path/elements/with%25esc/any%25where/to/file.txt");
50          }
51          final long endMillis = System.currentTimeMillis();
52  
53          System.err.println("time to resolve " + NUOF_RESOLVES + " children: " + (endMillis - startMillis) + " milliseconds");
54      }
55  
56      private static void testFiles(final FileSystemManager mgr) throws FileSystemException {
57          for (int i = 0; i < 10; i++) {
58              // warmup jvm
59              mgr.resolveFile(
60                      "smb://HOME\\vfsusr:vfs%2f%25\\te:st@10.0.1.54/vfsusr/many/path/elements/with%25esc/any%25where/to/file.txt");
61          }
62  
63          final long startMillis = System.currentTimeMillis();
64          for (int i = 0; i < NUOF_RESOLVES; i++) {
65              mgr.resolveFile(
66                      "smb://HOME\\vfsusr:vfs%2f%25\\te:st@10.0.1.54/vfsusr/many/path/elements/with%25esc/any%25where/to/file.txt");
67          }
68          final long endMillis = System.currentTimeMillis();
69  
70          System.err.println("time to resolve " + NUOF_RESOLVES + " files: " + (endMillis - startMillis) + " milliseconds");
71      }
72  
73      private static void testNames(final FileSystemManager mgr, final FileName rootName) throws FileSystemException {
74          for (int i = 0; i < 10; i++) {
75              // warmup jvm
76              mgr.resolveName(rootName, "/many/path/elements/with%25esc/any%25where/to/file.txt");
77          }
78  
79          final long startMillis = System.currentTimeMillis();
80          for (int i = 0; i < NUOF_RESOLVES; i++) {
81              mgr.resolveName(rootName, "/many/path/elements/with%25esc/any%25where/to/file.txt");
82          }
83          final long endMillis = System.currentTimeMillis();
84  
85          System.err.println("time to resolve " + NUOF_RESOLVES + " names: " + (endMillis - startMillis) + " milliseconds");
86      }
87  }