Without using a stop watch how can I determine how much time my computation actually took?
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
i type in terminal: time python programname.py and it shows it :D
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.
"i guess too bad if someone is a win user." You can say that again!! :)
too bad that windows user is using windows
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?
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.
Join our real-time social learning platform and learn together with your friends!