Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # http://python.assignmentsolutionguru.com/
- import datetime
- rand_word = "brunette"
- count = 10000
- count2 = 100
- def with_length():
- for i in range(count):
- result_str = list("_" * len(rand_word))
- def without_length():
- for i in range(count):
- result_str = [ '_' for c in rand_word ]
- if __name__ == '__main__':
- sum_with = 0
- for i in range(count2):
- start_with_length = datetime.datetime.now()
- with_length()
- end_with_length = datetime.datetime.now()
- sum_with += (end_with_length - start_with_length).microseconds
- sum_without = 0
- for i in range(count2):
- start_without_length = datetime.datetime.now()
- without_length()
- end_without_length = datetime.datetime.now()
- sum_without += (end_without_length - start_without_length).microseconds
- print("with_length() took microseconds (average):", sum_with / count2)
- print("without_length() took microseconds (average):", sum_without / count2)
- ### OUTPUT ###
- # RUN 1 #
- # with_length() took microseconds (average): 25097.74
- # without_length() took microseconds (average): 33223.47
- #
- # RUN 2 #
- # with_length() took microseconds (average): 22505.94
- # without_length() took microseconds (average): 30781.8
- #
- # RUN 3 #
- # with_length() took microseconds (average): 27909.81
- # without_length() took microseconds (average): 35745.27
- # http://python.assignmentsolutionguru.com/
Add Comment
Please, Sign In to add comment