I did try some of the suggestions using the zsh
$ time ./getdents keys | wc -l
./getdents keys 0,29s user 4,34s system 91% cpu 5,061 total
wc -l 0,11s user 0,13s system 4% cpu 5,061 total
$ time find keys -type f | wc -l
find keys -type f 10,38s user 7,82s system 3% cpu 7:42,05 total
wc -l 0,21s user 0,25s system 0% cpu 7:42,08 total
$ time ls -1 -U keys | wc -l
ls --color=tty -1 -U keys 3,88s user 6,69s system 2% cpu 7:53,60 total
wc -l 0,21s user 0,22s system 0% cpu 7:53,60 total
$ time python -c "import glob; print len(glob.glob('*'))"
python -c "import glob; print len(glob.glob('*'))" 8,20s user 12,37s system 1% cpu 32:00,29 total
The numbers they report differ because I was copying files out of the large directory at the same time (and because the find command also lists files in subdirectories which can be fixed by using
-maxdepth=1) and did not start all programs at the same time. However a general trend is clearly visible.
The first one is the C variant found in this thread linked by CodeIt.