def main(argv): iters = 1000000 start = time.time() my_squares_loops(iters) print("my_squares_loops takes %f s to run." % (time.time() - start)) start = time.time() my_squares_lc(iters) print("my_squares_lc takes %f s to run." % (time.time() - start))
def main(): """Compare run times of different string/list methods using time module """ # loops vs. list comprehensions: which is faster? iters = 1000000 start = time.time() my_squares_loops(iters) print("my_squares_loops takes %f s to run." % (time.time() - start)) start = time.time() my_squares_lc(iters) print("my_squares_lc takes %f s to run." % (time.time() - start)) # loops vs. the join method for strings: which is faster? mystring = "my string" start = time.time() my_join_join(iters, mystring) print("my_squares_loops takes %f s to run." % (time.time() - start)) start = time.time() my_join(iters, mystring) print("my_squares_lc takes %f s to run." % (time.time() - start)) return 0
## FUNCTIONS ## ############## # Compares the time for both squares functions using timeit # Commented out to avoid errors when running #%timeit my_squares_loops(iters) #%timeit my_squares_lc(iters) # Compares the time for both joins using timeit # Commented out to avoid errors when running #%timeit my_join_join(iters, mystring) #%timeit my_join(iters, mystring) # Times the non-optimised code start = time.time() my_squares_loops(iters) print("my_squares_loops takes %f s to run." % (time.time() - start)) # Times the optimised code start = time.time() my_squares_lc(iters) print("my_squares_lc takes %f s to run." % (time.time() - start))
__author__ = 'Jacob Griffiths ([email protected])' __version__ = '0.0.1' ############################################################################## # loops vs. list comprehensions: which is faster? ############################################################################## iters = 1000000 import timeit from profileme import my_squares as my_squares_loops from profileme2 import my_squares as my_squares_lc %timeit my_squares_loops(iters) %timeit my_squares_lc(iters) ############################################################################## # loops vs. the join method for strings: which is faster? ############################################################################## mystring = "my string" from profileme import my_join as my_join_join from profileme2 import my_join as my_join %timeit(my_join_join(iters, mystring)) %timeit(my_join(iters, mystring))