Warning: Can't synchronize with repository "(default)" (/home/git/ome.git does not appear to be a Git repository.). Look in the Trac log for more information.

Ticket #6586: HiddenTest.java

File HiddenTest.java, 2.7 KB (added by mlinkert, 7 years ago)

performance test case for File.isHidden alternatives

Line 
1package loci.formats;
2
3import java.io.File;
4import java.io.FileInputStream;
5import java.io.IOException;
6import java.nio.file.Files;
7import java.nio.file.Path;
8import java.nio.file.Paths;
9
10import org.apache.commons.vfs2.FileObject;
11import org.apache.commons.vfs2.FileSystemManager;
12import org.apache.commons.vfs2.VFS;
13
14public class HiddenTest {
15
16  private String file;
17  private long repeatCount;
18
19  public HiddenTest(String file, long repeatCount) {
20    this.file = file;
21    this.repeatCount = repeatCount;
22  }
23
24  public void run() {
25    testFileHidden();
26    testFilesHidden();
27    testDOSHidden();
28    testFileInputStream();
29    testVFSHidden();
30  }
31
32  private void testFileHidden() {
33    long t0 = System.currentTimeMillis();
34    for (long i=0; i<repeatCount; i++) {
35      File f = new File(file);
36      f.isHidden();
37    }
38    long t1 = System.currentTimeMillis();
39    logTime(t1 - t0, "java.io.File");
40  }
41
42  private void testFilesHidden() {
43    long t0 = System.currentTimeMillis();
44    for (long i=0; i<repeatCount; i++) {
45      Path p = Paths.get(file);
46      try {
47        Files.isHidden(p);
48      }
49      catch (IOException e) { }
50    }
51    long t1 = System.currentTimeMillis();
52    logTime(t1 - t0, "java.nio.file.Files");
53  }
54
55  private void testDOSHidden() {
56    long t0 = System.currentTimeMillis();
57    for (long i=0; i<repeatCount; i++) {
58      Path p = Paths.get(file);
59      try {
60        Files.getAttribute(p, "dos:hidden");
61      }
62      catch (IOException e) { }
63    }
64    long t1 = System.currentTimeMillis();
65    logTime(t1 - t0, "dos:hidden");
66  }
67
68  private void testFileInputStream() {
69    long t0 = System.currentTimeMillis();
70    for (long i=0; i<repeatCount; i++) {
71      try {
72        FileInputStream fis = new FileInputStream(file);
73        fis.read();
74        fis.close();
75      }
76      catch (IOException e) { }
77    }
78    long t1 = System.currentTimeMillis();
79    logTime(t1 - t0, "FileInputStream");
80  }
81
82  private void testVFSHidden() {
83    long t0 = System.currentTimeMillis();
84    try {
85      FileSystemManager fsManager = VFS.getManager();
86      for (long i=0; i<repeatCount; i++) {
87        FileObject fo = fsManager.resolveFile(file);
88        fo.isHidden();
89      }
90    }
91    catch (Exception e) {
92      e.printStackTrace();
93    }
94    long t1 = System.currentTimeMillis();
95    logTime(t1 - t0, "Apache Commons VFS");
96  }
97
98  private void logTime(long totalTime, String method) {
99    System.out.println(method + " total time (" + repeatCount + ")  calls: " + totalTime + " ms");
100    System.out.println(method + " avg time per call: " + (totalTime / (double) repeatCount) + " ms");
101  }
102
103  public static void main(String[] args) throws Exception {
104    HiddenTest test = new HiddenTest(args[0], Long.parseLong(args[1]));
105    test.run();
106  }
107
108}

1.3.13-PRO © 2008-2011 Agilo Software all rights reserved (this page was served in: 0.14110 sec.)

We're Hiring!