Commentary

  • Wow, this dude just found 11 legit (almost 13) ways to detect vowels in a string in python.Such a great depth, the benchmarks feels so intuitive as why each way performs the way it does.
  • Here are all the ways it did it
  • For loop: Simple, readable. Fastest for small strings
  • C-Styled for loop: Uses or comparisons, but surprisingly much slower
  • Nested for loop: Totally exhaustive, but slow
  • Set intersection: Clever and clean. Great when strings are long or vowels are sparse
  • Generator expression: Pythonic one-liner. Reasonably fast, readable
  • Recursion: Functional but inefficient. Crashes on long strings
  • Regex search: Shockingly fast. Calls C-level code internally
  • Regex replace: Works but inefficient. Doesn’t short-circuit
  • Filter: Readable but wasteful because it processes the whole string
  • Map: Similar to filter but slightly better
  • Prime Numbers: Extremely creative. Maps characters to primes, uses GCD. Way too slow to be practical
  • Would like to do something in Golang, it sounds so fun that I can’t stop thinking about so many ways to do so trivial things.