The Surprisingly Fast Way to Find Vowels in Strings

This article benchmarks eleven different methods for detecting vowels in strings, from simple loops to regular expressions and even a prime number-based approach. Surprisingly, regular expressions consistently outperform other methods, even simple loops, across various string lengths. A deep dive into Python bytecode and the CPython regex engine reveals the reason for regex's speed. The author concludes that while regex is fastest for most cases, simpler methods suffice unless dealing with millions of strings.
Read more