2121public class UnionFileSystemBenchmark {
2222 private static final UnionFileSystemProvider UFSP = (UnionFileSystemProvider ) FileSystemProvider .installedProviders ().stream ().filter (fsp ->fsp .getScheme ().equals ("union" )).findFirst ().orElseThrow (()->new IllegalStateException ("Couldn't find UnionFileSystemProvider" ));
2323 private static UnionFileSystem fileSystem ;
24+ private static UnionFileSystem dirFileSystem ;
25+ private static Path rawdir ;
2426
2527 @ Setup
2628 public void setup () throws Exception {
27- var path1 = Paths .get ("./ src/jmh/resources/ testjar1.jar" );
28- var path2 = Paths .get ("./ src/jmh/resources/ testjar2.jar" );
29- var path3 = Paths .get ("./ src/jmh/resources/ testjar3.jar" );
29+ var path1 = Paths .get ("src" , "testjars" , " testjar1.jar"). toAbsolutePath (). normalize ( );
30+ var path2 = Paths .get ("src" , "testjars" , " testjar2.jar"). toAbsolutePath (). normalize ( );
31+ var path3 = Paths .get ("src" , "testjars" , " testjar3.jar"). toAbsolutePath (). normalize ( );
3032 Map <String , List <Path >> properties = new HashMap <>();
3133 var additionalPaths = List .of (path2 , path3 );
3234 properties .put ("additional" , additionalPaths );
3335
3436 fileSystem = (UnionFileSystem ) UFSP .newFileSystem (path1 , properties );
37+ rawdir = Paths .get ("src" ,"testrawdir" ).toAbsolutePath ().normalize ();
38+ var dir2 = Paths .get ("src" , "testrawdir2" ).toAbsolutePath ().normalize ();
39+ dirFileSystem = (UnionFileSystem ) UFSP .newFileSystem (rawdir , Map .of ("additional" , List .of (dir2 )));
3540 }
3641
3742 @ Benchmark
38- public void testFileExists (Blackhole blackhole ) throws Exception {
43+ public void testJarFileExists (Blackhole blackhole ) throws Exception {
3944 runExists ("cpw/mods/niofs/union/UnionPath.class" , true ); //jar 1
4045 runExists ("net/minecraftforge/client/event/GuiOpenEvent.class" , true ); //jar 2
4146 runExists ("cpw/mods/modlauncher/Launcher.class" , true ); //jar 3
47+ }
48+ @ Benchmark
49+ public void testJarFileNotExists (Blackhole blackhole ) throws Exception {
4250 runExists ("cpw/mods/modlauncher/api/NoIDontExist.class" , false );
4351 runExists ("net/minecraftforge/client/nonexistent/Nope.class" , false );
4452 runExists ("Missing.class" , false );
4553 }
4654
4755 @ Benchmark
56+ public void testNativeFileExists (Blackhole blackhole ) throws Exception {
57+ runNativeFileExists ("ThisFileExists.txt" , true );
58+ runNativeFileExists ("ThisFileExists2.txt" , true );
59+ runNativeFileExists ("ThisFileExists3.txt" , true );
60+ }
61+ @ Benchmark
62+ public void testNativeFileNotExists (Blackhole blackhole ) throws Exception {
63+ runNativeFileNotExists ("ThisFileNotExists.txt" , true );
64+ runNativeFileNotExists ("ThisFileNotExists2.txt" , true );
65+ runNativeFileNotExists ("ThisFileNotExists3.txt" , true );
66+ }
67+
68+ // @Benchmark
69+ public void testNativeFileExistsNegative (Blackhole blackhole ) throws Exception {
70+ runNativeFileNotExists ("ThisFileExists.txt" , false );
71+ runNativeFileNotExists ("ThisFileExists2.txt" , false );
72+ runNativeFileNotExists ("ThisFileExists3.txt" , false );
73+ }
74+ // @Benchmark
75+ public void testNativeFileNotExistsNegative (Blackhole blackhole ) throws Exception {
76+ runNativeFileExists ("ThisFileNotExists.txt" , false );
77+ runNativeFileExists ("ThisFileNotExists2.txt" , false );
78+ runNativeFileExists ("ThisFileNotExists3.txt" , false );
79+ }
80+
81+ // @Benchmark
4882 public void testDirectoryStream (Blackhole blackhole ) throws Exception {
4983 runDirStream ("cpw/mods/jarhandling" , 5 , blackhole ); //jar 1
5084 runDirStream ("net/minecraftforge/common" , 72 , blackhole ); //jar 2
5185 runDirStream ("cpw/mods/modlauncher/api" , 34 , blackhole ); //jar 3
5286 }
5387
54- @ Benchmark
88+ // @Benchmark
5589 public void testByteChannel (Blackhole blackhole ) throws Exception {
5690 runByteChannel ("cpw/mods/niofs/union/UnionPath.class" , blackhole ); //jar 1
5791 runByteChannel ("net/minecraftforge/client/event/GuiOpenEvent.class" , blackhole ); //jar 2
5892 runByteChannel ("cpw/mods/modlauncher/Launcher.class" , blackhole ); //jar 3
5993 }
6094
61- @ Benchmark
95+ // @Benchmark
6296 public void testReadAttributes (Blackhole blackhole ) throws Exception {
6397 runReadAttributes ("cpw/mods/niofs/union/UnionPath.class" , 9550 , blackhole ); //jar 1
6498 runReadAttributes ("net/minecraftforge/client/event/GuiOpenEvent.class" , 782 , blackhole ); //jar 2
6599 runReadAttributes ("cpw/mods/modlauncher/Launcher.class" , 12648 , blackhole ); //jar 3
66100 }
67101
68- @ Benchmark
102+ // @Benchmark
69103 public void testCommonPathUtilities (Blackhole blackhole ) throws Exception {
70104 var path = fileSystem .getPath ("net/minecraftforge/client/event/GuiOpenEvent.class" );
71105 blackhole .consume (path .getFileName ());
@@ -74,6 +108,18 @@ public void testCommonPathUtilities(Blackhole blackhole) throws Exception {
74108 blackhole .consume (path .subpath (0 , 3 ));
75109 }
76110
111+ private static void runNativeFileExists (String pathString , boolean expected ) throws Exception {
112+ if (Files .exists (dirFileSystem .getPath (pathString )) != expected ) {
113+ throw new RuntimeException ("Wrong exists status" );
114+ }
115+ }
116+
117+ private static void runNativeFileNotExists (String pathString , boolean expected ) throws Exception {
118+ if (Files .notExists (dirFileSystem .getPath (pathString )) != expected ) {
119+ throw new RuntimeException ("Wrong exists status" );
120+ }
121+ }
122+
77123 private static void runExists (String pathString , boolean expected ) throws Exception {
78124 if (Files .exists (fileSystem .getPath (pathString )) != expected ) {
79125 throw new RuntimeException ("Wrong exists status" );
0 commit comments