Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. import timeit
  2.  
  3. class app:
  4.  
  5. def __init__(self):
  6. self.txt = "Hello"
  7.  
  8. def ec(self):
  9.  
  10. x = self.txt.casefold()
  11.  
  12. def myImplementation(self):
  13. tekst = ''
  14. for i in range(len(self.txt)):
  15. c = ord(self.txt[i])
  16. if c > 64 and c < 90:
  17. c = c + 32
  18. tekst += chr(c)
  19.  
  20. def run(self):
  21. self.time = timeit.Timer("d.ec()","from __main__ import app; d = app()")
  22. firstTime = self.time.timeit(number=10)
  23. print(firstTime)
  24. self.time = timeit.Timer("d.myImplementation()","from __main__ import app; d = app()")
  25. secondTime = self.time.timeit(number=10)
  26. print(secondTime)
  27. finalTime = secondTime / firstTime
  28. print("Final Time " + str(finalTime))
  29.  
  30.  
  31. if __name__ == "__main__":
  32. a = app()
  33. a.run()
  34. a.myImplementation()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement