Adamish
May 16, 2022

--

FWIW, I pasted those solutions into an online benchmarking tool: https://perfpy.com/50

The last example doesn't seem to run as-is. I'm low on energy and not a Pythonista; I did the bare minimum to get it to work.

The last, tersest*, one seems to be ~3000x worse in terms of speed. The others are much of a muchness, almost identical. I ran the benchmark a few times and 1, 2, and 3 switched places almost every time; none was so much more performant that it took the number one spot every time.

So, even more of a reason to avoid code-golf!

The first rule of optimisation club is "profile your code!"

* To be fair, terseness often seems to be the primary goal of golfing solutions, over performance.

--

--

Adamish

I’m a Lead Developer and write mostly Ruby on Rails. I also dabble in any language that takes my fancy.