Optimizing C++ Word Count
Yesterday’s post showed that the original C++ version is around 13 times slower than my non-optimized Rust version. Next, I’ll show how to get easily equivalent performance to Rust.
One problem that I immediately made out when first seeing the C++ version is
that it uses std::regex. std::regex is known to be horribly slow 1.
Just replacing the checking of the file name extension with the in-built
e.path().extension() != ".txt" speeds up from 373 ms to 52ms!