Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. import cProfile
  2.  
  3.  
  4. def profile_this(fn):
  5. def profiled_fn(*args, **kwargs):
  6. filename = fn.__name__ + '.profile'
  7. prof = cProfile.Profile()
  8. ret = prof.runcall(fn, *args, **kwargs)
  9. prof.dump_stats(filename)
  10. return ret
  11. return profiled_fn
  12.  
  13. if __name__ == '__main__':
  14. def f1():
  15. a = [x * x for x in range(10000)]
  16. return a
  17.  
  18. def f2():
  19. a = [x * x for x in range(20000)]
  20. return a
  21.  
  22. def f3():
  23. a = [x * x for x in range(30000)]
  24. return a
  25.  
  26. @profile_this
  27. def test():
  28. f1()
  29. f2()
  30. f3()
  31.  
  32. test()
  33. print('Profile is available in test.profile.'
  34. 'Use runsnake or snakeviz to view it')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement