Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 11 Online
OpenStudy (anonymous):

Without using a stop watch how can I determine how much time my computation actually took?

OpenStudy (anonymous):

I wanted a way to test which algorithms are faster. Here is some python code that you can use to determine how much time it took for a computation and, therefore, compare different algorithm efficiencies. #import the time library import time #get a reading of the clock and assign that to variable start start=time.clock() #carry out some computation end=time.clock() time_elapsed=end - start print time_elapsed

OpenStudy (anonymous):

i type in terminal: time python programname.py and it shows it :D

OpenStudy (anonymous):

very cool Tomas. terminal also gives breakdown. alas, you have to have access to terminal. :) i guess too bad if someone is a win user.

OpenStudy (mathmate):

"i guess too bad if someone is a win user." You can say that again!! :)

OpenStudy (anonymous):

too bad that windows user is using windows

OpenStudy (anonymous):

Do you suppose there is a way to get a print statement to kick out a float value in time? Anybody know of a way to get a time stamp when it's called for, then essentially "create" a stopwatch in the program?

OpenStudy (mathmate):

In Java, use System.nanoTime(). But do beware that in Java, elapse time varies a lot because of memory management (e.g. garbage collection) behind the scenes.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!