Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. $ python
  2. Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
  3. [GCC 4.4.5] on linux2
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>> import time
  6. >>> from decorator import decorator
  7. >>>
  8. >>> @decorator
  9. ... def timer(func, *args, **kws):
  10. ...     t = time.time()
  11. ...     res = func(*args, **kws)
  12. ...     print 'Время выполнения функции %s: %f' % \
  13. ...         (func.__name__, time.time()-t)
  14. ...     return res
  15. ...
  16. >>> @timer
  17. ... def str_concat_test_1(a, b):
  18. ...     for i in xrange(1000000):
  19. ...         s = '%s%s' % (a, b)
  20. ...
  21. >>> @timer
  22. ... def str_concat_test_2(a, b):
  23. ...     for i in xrange(1000000):
  24. ...         s = a + b
  25. ...
  26. >>> @timer
  27. ... def str_concat_test_3(a, b):
  28. ...     for i in xrange(1000000):
  29. ...         s = ''.join((a, b))
  30. ...
  31. >>> str_concat_test_1('Nya ', 'kawaii')
  32. Время выполнения функции str_concat_test_1: 0.382882
  33. >>> str_concat_test_2('Nya ', 'kawaii')
  34. Время выполнения функции str_concat_test_2: 0.132083
  35. >>> str_concat_test_3('Nya ', 'kawaii')
  36. Время выполнения функции str_concat_test_3: 0.306145
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement