Right answer : They're both the same length of a fraction.
But which faster if subject
is time
?
A little test case :
import timeit
import time
clock_list = []
time_list = []
test1 = """
def test(v=time.clock()):
s = time.clock() - v
"""
test2 = """
def test(v=time.time()):
s = time.time() - v
"""
def test_it(Range) :
for i in range(Range) :
clk = timeit.timeit(test1, number=10000)
clock_list.append(clk)
tml = timeit.timeit(test2, number=10000)
time_list.append(tml)
test_it(100)
print "Clock Min: %f Max: %f Average: %f" %(min(clock_list), max(clock_list), sum(clock_list)/float(len(clock_list)))
print "Time Min: %f Max: %f Average: %f" %(min(time_list), max(time_list), sum(time_list)/float(len(time_list)))
I am not work an Swiss labs but I've tested..
Based of this question : time.clock()
is better than time.time()
Edit : time.clock()
is internal counter so can't use outside, got limitations max 32BIT FLOAT
, can't continued counting if not store first/last values. Can't merge another one counter...
time.clock()
is deprecated, and it is recommended to useperf_counter()
orprocess_time()
instead. – Cody Piersalltimeit.default_timer()
to measure performance (it is assigned to time.time() or time.clock() depending on OS). – jfstime.clock
andtime.process_time
, but child processes are not. Also see this discussion of precision (of course, varies by system). – max