Commit 85526a2
committed
Check the pattern before anything else, since it doesn't require metadata
This should partially address #432 by decreasing the number of stat() calls:
$ strace -c -f ./fd-before '.h$' -j1 /usr -S +1k >/dev/null
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
100.00 3.700169 3 983938 38022 stat
$ strace -c -f ./fd-after '.h$' -j1 /usr -S +1k >/dev/null
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
100.00 0.671723 4 162052 38021 stat
Though it's not as good as possible:
$ strace -c -f find /usr -name '*.h' -size +1k >/dev/null
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
18.75 0.449866 3 136199 newfstatat
$ strace -c -f bfs /usr -name '*.h' -size +1k >/dev/null
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
15.01 0.216024 3 60211 1 statx
Performance is much better when metadata is required:
$ hyperfine ./fd-{before,after}" '.h$' -j1 /usr -S +1k"
Benchmark #1: ./fd-before '.h$' -j1 /usr -S +1k
Time (mean ± σ): 2.707 s ± 0.042 s [User: 890.8 ms, System: 1939.7 ms]
Range (min … max): 2.659 s … 2.786 s 10 runs
Benchmark #2: ./fd-after '.h$' -j1 /usr -S +1k
Time (mean ± σ): 1.562 s ± 0.034 s [User: 726.2 ms, System: 957.9 ms]
Range (min … max): 1.536 s … 1.648 s 10 runs
Summary
'./fd-after '.h$' -j1 /usr -S +1k' ran
1.73 ± 0.05 times faster than './fd-before '.h$' -j1 /usr -S +1k'
While remaining the same when it's not:
tavianator@graviton $ hyperfine ./fd-{before,after}" '.h$' -j1 /usr"
Benchmark #1: ./fd-before '.h$' -j1 /usr
Time (mean ± σ): 1.341 s ± 0.016 s [User: 664.3 ms, System: 761.2 ms]
Range (min … max): 1.309 s … 1.361 s 10 runs
Benchmark #2: ./fd-after '.h$' -j1 /usr
Time (mean ± σ): 1.338 s ± 0.012 s [User: 684.1 ms, System: 741.1 ms]
Range (min … max): 1.310 s … 1.350 s 10 runs
Summary
'./fd-after '.h$' -j1 /usr' ran
1.00 ± 0.02 times faster than './fd-before '.h$' -j1 /usr'1 parent 35945c4 commit 85526a2
1 file changed
+25
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
270 | 291 | | |
271 | 292 | | |
272 | 293 | | |
| |||
294 | 315 | | |
295 | 316 | | |
296 | 317 | | |
297 | | - | |
298 | | - | |
299 | 318 | | |
300 | 319 | | |
301 | 320 | | |
| |||
345 | 364 | | |
346 | 365 | | |
347 | 366 | | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
367 | 371 | | |
368 | 372 | | |
369 | 373 | | |
| |||
0 commit comments