[Tutor] How to find optimisations for code

Alan Gauld alan.gauld at yahoo.co.uk
Fri Oct 19 18:07:15 EDT 2018

On 19/10/18 17:12, Pat Martin wrote:

> TLDR; How do you figure out if code is inefficient (if it isn't necessarily
> obvious) and how do you find a more efficient solution?

Others have addressed most of the issues but I'd just add the caveat
that you can spend forever trying to make your code "more efficient".
Usually, in the real world, you don't need to.

So how do you figure out if your code is inefficient?
Run it and if it doesn't work fast enough for your purpose then
try to speed it up. If it does then move onto the next project.

> how do I go about finding a more efficient solution?

Google, a good reference book and experience.

But always, always, measure because there has been more
time wasted on unnecessary optimisations than on any other
feature of programming.

Alan G
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:

More information about the Tutor mailing list