Advertisement
desdemona

:(

Oct 13th, 2015
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. import sys
  2. import uuid
  3. import timeit
  4.  
  5.  
  6.  
  7. def my_concat(s1, s2):
  8.     return str(s1).join(str(s2))
  9.  
  10.  
  11. def str_add(s1, s2):
  12.     return s1 + s2
  13.  
  14. if __name__ == '__main__':
  15.     digits = 0
  16.     tests = 0
  17.  
  18.     if len(sys.argv) < 3:
  19.         print("[liczba znakow na string] [ilosc testow]")
  20.         sys.exit()
  21.  
  22.     digits = int(sys.argv[1])
  23.     tests = int(sys.argv[2])
  24.  
  25.     my_concat_total = 0
  26.     normal_add_total = 0
  27.  
  28.     for i in range(0, tests):
  29.         a = b = c1 = c2 = ""
  30.  
  31.         a = b = c1 = c2 = ""
  32.         while len(a) < digits:
  33.             a += str(uuid.uuid4())
  34.             b += str(uuid.uuid4())
  35.  
  36.         a = a[0:digits]
  37.         b = b[0:digits]
  38.  
  39.         my_time = timeit.timeit('my_concat("'+a+'", "'+b+'")', setup="from __main__ import my_concat")
  40.         normal_time = timeit.timeit('str_add("'+a+'", "'+b+'")',  setup="from __main__ import str_add")
  41.  
  42.         my_concat_total += my_time
  43.         normal_add_total += normal_time
  44.  
  45.         print(str(normal_time) + "," + str(my_time) + "\n")
  46.  
  47.     print("my concat in total: " + str(my_concat_total) + "\n")
  48.     print("normal concat total: " + str(normal_add_total) + "\n")
  49.     print("my concat avg: " + str(my_concat_total/tests) + "\n")
  50.     print("normal concat avg: " + str(normal_add_total/tests) + "\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement