Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import uuid
- import time
- def my_concat(s1, s2):
- return s1.join(s2)
- def str_add(s1, s2):
- return s1 + s2
- if __name__ == '__main__':
- digits = 0
- tests = 0
- if len(sys.argv) < 3:
- print("[liczba znakow na string] [ilosc testow]")
- sys.exit()
- digits = int(sys.argv[1])
- tests = int(sys.argv[2])
- my_concat_total = 0
- normal_add_total = 0
- for i in range(0, tests):
- a = b = c1 = c2 = ""
- a = b = c1 = c2 = ""
- while len(a) < digits:
- a += str(uuid.uuid4())
- b += str(uuid.uuid4())
- a = a[0:digits]
- b = b[0:digits]
- #my_time = timeit.timeit('my_concat("'+a+'", "'+b+'")', setup="from __main__ import my_concat")
- #normal_time = timeit.timeit('str_add("'+a+'", "'+b+'")', setup="from __main__ import str_add")
- start_time = time.time()
- c1 = my_concat(a, b)
- my_time = time.time() - start_time
- start_time = time.time()
- c2 = str_add(a, b)
- normal_time = time.time() - start_time
- my_concat_total += my_time
- normal_add_total += normal_time
- print("%.20f" % normal_time + "," + "%.20f" % my_time + "\n")
- print("my concat in total: " + str(my_concat_total) + "\n")
- print("normal concat total: " + str(normal_add_total) + "\n")
- print("my concat avg: " + str(my_concat_total/tests) + "\n")
- print("normal concat avg: " + str(normal_add_total/tests) + "\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement