timing solutions for Euler

This is the place for queries that don't fit in any of the other categories.

timing solutions for Euler

Postby mnutz » Tue Nov 26, 2013 5:58 am

Hey all,

I've picked up Python again, built my second program and instead of just leaving it and forgetting it all like I do all the time I've decided to jump in to as much as possible and taking on Project Euler too.

Silly question I am sure, but how would you go about timing how long it takes to complete a solution?

I've seen it somewhere in the last few days but can't find it anywhere now :(
Posts: 10
Joined: Sun Nov 17, 2013 8:11 am

Re: timing solutions for Euler

Postby micseydel » Tue Nov 26, 2013 7:22 am

If you're using Linux or OS X you can type "time" before your Python invocation. Otherwise you can use timeit.
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: timing solutions for Euler

Postby zeycus » Tue Nov 26, 2013 4:01 pm

There is a module called 'timeit' that is precisely built for that:
I guess this is really the way to go.

If the times you are measuring are not too short and you don't need a lot of precision, you can also write

Code: Select all
... execute your code

You will get the number of seconds elapsed.

Live long and prosper.
User avatar
Posts: 23
Joined: Sun Feb 17, 2013 10:30 am
Location: Madrid

Re: timing solutions for Euler

Postby mnutz » Wed Nov 27, 2013 3:38 pm

thank you both for the info :D
Posts: 10
Joined: Sun Nov 17, 2013 8:11 am

Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 10 guests