[Tutor] compile time calculator

Alan Gauld alan.gauld at btinternet.com
Fri Jan 27 20:35:35 CET 2012


On 27/01/12 15:46, Surya K wrote:

> I want to calculate compile time for my puzzles.

I'm pretty sure from what follows you don't!
But just to be clear, compile time is the time Python spends converting 
your modules into .pyc files the first time they are imported after a 
change. Why you would want to time that I have no idea, and assume you 
don't really.

>  Although I read about timeit(),

timeit is used to measure *execution* times, it has nothing to do with 
compile times.

However, if you want to measure how long your code takes to run then it 
is relevant. Search the archive of this list for some good examples of 
using timeit. I seem to recall Steven wrote an excellent tutorial a few 
months ago.

> I am looking for a function which should solve my puzzle and also show
> compile time. (Later, I should be able to delete that function before
> submitting my code)

I'm afraid you'll need to solve the puzzle yourself. There is unlikely 
to be a ready made one lying around and folks on this list can help but 
we do not do your work for you. (And in this case couldn't since we 
don't know what your puzzle is! Or are you still talking about the Lucky 
numbers one from earlier?)

> define a compile time function such that it should take all my puzzle
> code and provide compile time for it.
>
> (I think timeit() should be called at each statement, which is not
> flexible, don't know exactly.)

Assuming you want run time not compile time you should probably look at 
the Python profiler - in the profile module. It's not totally intuitive 
to set up but the documents give examples. But it doesn't work at the 
line level but at functions.

But if you are still battling with the Lucky Number thing you really 
need to go back to the math, not the Python code. You need a new 
algorithm not tighter code. Wikipedia and Google might be more help than 
the profiler!

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list