20:fc0904a91aea default tip
Anton Shestakov <engored@ya.ru>, Sat, 29 Nov 2014 13:29:52 +0800
find-closest: something about ok and fail

previous change 19:29f1205cdc33

find-closest/README.md

Permissions: -rw-r--r--

Other formats: Feeds:
This is a benchmark for some different methods of searching for a file/dir
upwards in a filesystem hierarchy. Disclaimer: the code is pretty ad-hoc and
hairy.
Finding a specific file/dir in parent directories is useful as a fast
preliminary check before running more complex and potentially slower commands.
Such use case is checking if directory is tracked in a version control system,
and in this particular case — mercurial. So here all `hgroot_*.sh` files search
for a `.hg/` directory upwards.
Here's the output of `test.sh`:
not tracked
builtins dirname upsearch
ok 0.292 ok 0.577 ok 0.207
ok 0.295 ok 0.700 ok 0.218
ok 0.303 ok 0.836 ok 0.234
ok 0.306 ok 0.967 ok 0.261
ok 0.324 ok 1.147 ok 0.254
ok 0.271 ok 1.248 ok 0.260
ok 0.344 ok 1.387 ok 0.261
ok 0.339 ok 1.555 ok 0.267
ok 0.327 ok 1.722 ok 0.274
ok 0.343 ok 1.734 ok 0.277
tracked in mercurial
builtins dirname upsearch
ok 0.294 ok 0.330 ok 0.203
ok 0.292 ok 0.466 ok 0.228
ok 0.305 ok 0.666 ok 0.230
ok 0.306 ok 0.729 ok 0.225
ok 0.309 ok 0.848 ok 0.231
ok 0.316 ok 0.997 ok 0.250
ok 0.315 ok 1.139 ok 0.242
ok 0.324 ok 1.202 ok 0.244
ok 0.314 ok 1.323 ok 0.253
ok 0.324 ok 1.471 ok 0.274
- `builtins` = `hgroot_1.sh`, `dirname` = `hgroot_2.sh` and `upsearch` =
`hgroot_3.sh`
- results are in seconds x 100, that is, 0.292 is how many a hundred calls to
the command takes, so each call is ~2.92ms
- `ok` means the command ran correctly
First the test script runs (100 times for a good measure) all contestant
implementations in directories without a `.hg/` anywhere upwards (assuming your
`/` or `/tmp` is untracked), one directory deeper at a time: so the last result
is for the case when the script is 10 directories deep inside `/tmp/tmp.XXX/`
directory (test root). Then the test script adds an empty `.hg/` directory in
the test root and runs everything one more time. It also checks that the
contestants produce the correct answer (path to the directory containing
`.hg/`) and marks the time with either `ok` or `fail`. There are quirks, as I
said, but I believe the results are fairly accurate still.