This command combines ls (directory list) with wc (word count) command to count the number of files in a directory. I just used it to count over 100k files in a directory and it ran pretty fast, under a second.
ls -1 | wc -l
Output + time
time ls -1 | wc -l
101000
real 0m0.662s
user 0m0.616s
sys 0m0.039s