Karsol

Untitled

Apr 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. import time
  2.  
  3. def string_splosion1(str):
  4. newString = ''
  5. for i in range(len(str)):
  6. x = len(str) - i
  7. negNum = x * -1
  8. newString = newString + str[:negNum]
  9. newString += str
  10. return newString
  11.  
  12.  
  13.  
  14. def string_splosion2(str):
  15. result = ""
  16. for i in range(len(str)):
  17. result = result + str[:i+1]
  18. return result
  19.  
  20.  
  21. n = 10000
  22. t0 = time.time()
  23. for i in range(n): string_splosion1('Code')
  24. t1 = time.time()
  25.  
  26. t2 = time.time()
  27. for x in range(n): string_splosion2('Code')
  28. t3 = time.time()
  29.  
  30. total_n = t1-t0
  31. total_z = t3-t2
  32. print(total_n)
  33. print(total_z)
Advertisement
Add Comment
Please, Sign In to add comment