Skip to content

Commit 750e133

Browse files
committed
Update benchmark to use Files.walkFileTree and add run-benchmark.bat
1 parent e28251f commit 750e133

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

examples/Benchmark/src/main/java/fastfileindex/Benchmark.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,15 @@ private static long runFastFileIndex(String path, boolean warmup) {
3939
if (!warmup) System.out.print("FastFileIndex: ");
4040

4141
long start = System.currentTimeMillis();
42-
AtomicLong count = new AtomicLong(0);
4342

44-
FastFileIndex.buildWithProgress(new String[]{path}, new ProgressCallback() {
45-
@Override
46-
public void onProgress(String currentFile, long totalFiles, long currentPath) {
47-
count.incrementAndGet();
48-
}
49-
});
43+
FastFileIndex.build(new String[]{path});
5044

5145
long end = System.currentTimeMillis();
5246
long elapsed = end - start;
5347

5448
if (!warmup) {
55-
System.out.println(elapsed + " ms (" + count.get() + " files)");
49+
long count = FastFileIndex.getEntryCount();
50+
System.out.println(elapsed + " ms (" + count + " files)");
5651
}
5752

5853
return elapsed;
@@ -65,9 +60,20 @@ private static long runJavaWalk(String path, boolean warmup) {
6560
AtomicLong count = new AtomicLong(0);
6661

6762
try {
68-
Files.walk(Paths.get(path))
69-
.filter(Files::isRegularFile)
70-
.forEach(file -> count.incrementAndGet());
63+
Files.walkFileTree(Paths.get(path), new SimpleFileVisitor<Path>() {
64+
@Override
65+
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
66+
if (attrs.isRegularFile()) {
67+
count.incrementAndGet();
68+
}
69+
return FileVisitResult.CONTINUE;
70+
}
71+
72+
@Override
73+
public FileVisitResult visitFileFailed(Path file, IOException exc) {
74+
return FileVisitResult.CONTINUE;
75+
}
76+
});
7177
} catch (IOException e) {
7278
System.err.println("Error: " + e.getMessage());
7379
}

run-benchmark.bat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@echo off
2+
javac -cp target\fastfileindex-v1.0.0.jar examples\Benchmark\src\main\java\fastfileindex\Benchmark.java -d examples\Benchmark\src\main\java
3+
cd build
4+
java --enable-native-access=ALL-UNNAMED -cp ..\target\fastfileindex-v1.0.0.jar;..\examples\Benchmark\src\main\java fastfileindex.Benchmark

0 commit comments

Comments
 (0)