36
pily
6y

This spring I was working on a library for an algorithm class at uni with some friends and one of the algorithm was extremely slow, we were using Python to study graphs of roads on a map and a medium example took about 6-7h of commission to finish (I never actually waited for so long, so maybe more).
I got so pissed of for that code that I left the lab and went to eat. Once I got back I rewrote just the god-damned data structure we were using and the time got down to 300ms. Milliseconds!

Lessons learned:
- If you're pissed go take a walk and when you'll come back it will be much easier;
- Don't generalize to much a library, the data structure I write before was optimized for a different kind of usage and complete garbage for that last one;
- Never fucking use frozen sets in Python unless you really need them, they're so fricking slow!

Comments
  • 8
    Damn, even I got a bonner from this one
  • 7
    In Kurt Guntheroth's book Optimizing C++, he mentions a case in which he helped fix an Air Force simulation program in which some idiot had used bubble sort (or some such crap). Switching to a faster sort decreased the runtime by an insane amount (I forget whether it was hours or weeks).

    Moral of the story: know your tools, and know your craft! (data structures and algorithms)
  • 1
    @RememberMe I absolutely agree with you, if you don't know what you're working with you're basically aiming at a ghost 😂. In this case it was my, and my teammates, first time using Python for a real project, so we were in that position more or less.
Add Comment