

Ask HN: Why does running a few instances of DIR /s in Command prompt load CPU heavily? - fzkl

Opening 3-5 windows command prompt and running DIR /S to list all subdirectories increases CPU load to 80%. I have seen this type of significant load on the CPU in different platforms. Any idea why a simple task like directory listing consumes so much CPU?
======
jacquesm
That's because you are the only user on the system and you're asking the
filesystem to tell you everything it knows about all your files.

Strictly speaking it is an io-bound operation, but with the number of files on
your machine and some aggressive caching it will quickly turn into a memory-
to-display translation (involving lots of font rendering and scrolling) and
that is cpu-bound, not io-bound.

Look at it this way, the 'idle' process also consumes lots of cpu power, but
it does absolutely nothing. When you're alone on a machine you have the power
to max it out with anything cpu bound, no matter how simple. A loop that
counts from 0 to 1.000.000.000 (assuming it's not optimized out) will consume
100% cpu time unless you tell your system explicitly otherwise.

The only way to _not_ max out the cpu is to deliberately slow the process down
by installing small sleep periods in between operations, but you really want
your 'dir /s' to run as fast as it can.

~~~
gaius
Indeed - as an experiment, try doing the same with all your CMD windows
minimized.

~~~
fzkl
Thanks

