More tests, some process profiling and some debug later.
Instead of trying to remove the efect of the cache, I've made repetitive queries to ensure "all"? of the file/folder structure is cached by the OS, suspended almost anything else and then executed the tests to see if there is a significative difference in how both commands handle the data.
Code: Select all
[W:\]:# gett dir d:\ /s /b ^> list
0 days 00:00:08.315
[W:\]:# gett dir d:\ /s /b ^> list
0 days 00:00:08.269
[W:\]:# dir list | find "list"
22/06/2015 11:01 28.016.937 list
[W:\]:# find /c /v "" < list
351858
[W:\]:# gett for /f "usebackq delims=" %a in ("list") do @rem
0 days 00:00:00.656
[W:\]:# gett for /f "usebackq delims=" %a in ("list") do @rem
0 days 00:00:00.663
[W:\]:# gett for /r "d:\" %a in (*) do @rem
0 days 00:00:06.880
[W:\]:# gett for /r "d:\" %a in (*) do @rem
0 days 00:00:06.671
"procmon" shows that both "dir" and "for /r" commands use similar queries to retrieve the recursive file/folder information, but the debugger shows more code in the "dir" command to deal with all the available output options. This and the file write operation gives a little avantage to the "for /r" approach over the combined "dir" + "for /f" with a temporary file. But unless a few seconds are critical, the difference is not really significative. The bigger cost is the iteration over the file system both commands need.
But
Then, just to measure the cost of the file generation, as it is inexistent in the "for /r" test, I have found something I didn't expect (I don't know if it is a known thing, I didn't knew it).
Code: Select all
[W:\]:# gett dir d:\ /s /b ^> list
0 days 00:00:08.371
[W:\]:# gett dir d:\ /s /b ^> nul
0 days 00:00:52.664
[W:\]:# gett dir d:\ /s /b ^> nul
0 days 00:00:50.996
[W:\]:# gett dir d:\ /s /b ^> list
0 days 00:00:08.341
[W:\]:# gett dir d:\ /s /b ^> list
0 days 00:00:08.366
[W:\]:# gett type list ^> nul
0 days 00:00:04.197
[W:\]:# gett type list ^> nul
0 days 00:00:05.917
[W:\]:# gett type list ^> nul
0 days 00:00:05.873
[W:\]:# gett type list ^> list2
0 days 00:00:00.789
[W:\]:# gett type list ^> list2
0 days 00:00:00.768
[W:\]:# gett type list ^> list2
0 days 00:00:00.762
At least in my systems (XP, 32b W7, 64b W7) , the "dir" and "type" commands are very inefficient writing to the nul device. Something that does not happen with piped versions or external commands
Code: Select all
[W:\]:# gett dir d:\ /s /b ^| find /v "" ^> nul
0 days 00:00:07.849
[W:\]:# gett dir d:\ /s /b ^| find /v "" ^> nul
0 days 00:00:07.611
[W:\]:# gett dir d:\ /s /b ^| find /v "" ^> list2
0 days 00:00:07.764
[W:\]:# gett dir d:\ /s /b ^| find /v "" ^> list2
0 days 00:00:07.795
[W:\]:# gett findstr "^" ^< list ^>nul
0 days 00:00:00.237
[W:\]:# gett findstr "^" ^< list ^>nul
0 days 00:00:00.245
[W:\]:# gett findstr "^" ^< list ^>list2
0 days 00:00:00.208
[W:\]:# gett findstr "^" ^< list ^>list2
0 days 00:00:00.195