Guest User

Untitled

a guest
Aug 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. from memory_profiler import profile
  2. import random
  3. import hug
  4.  
  5. @profile
  6. def random_list(quantity):
  7. result = []
  8. for i in range(1, quantity+1):
  9. result.append((i, random.randint(0, 9)))
  10.  
  11. return result
  12.  
  13. @profile
  14. def random_list_comprehension(quantity):
  15. return [(i, random.randint(0, 9)) for i in range(1, quantity+1)]
  16.  
  17. @profile
  18. def random_list_generator(quantity):
  19. for i in range(1, quantity+1):
  20. yield (i, random.randint(0,9))
  21.  
  22. @profile
  23. def random_list_generator_expression(quantity):
  24. return ((i, random.randint(0, 9)) for i in range(1, quantity+1))
  25.  
  26. @hug.cli()
  27. def cli(quantity: hug.types.number):
  28. random_list(quantity)
  29. print('Profile random_list called:')
  30. print('===================================================================')
  31.  
  32. random_list_comprehension(quantity)
  33. print('Profile random_list_comprehension called:')
  34. print('===================================================================')
  35.  
  36. print('Profile random_list_generator:', random_list_generator(quantity))
  37. print('===================================================================')
  38.  
  39. print('Profile random_list_generator_expression:', random_list_generator_expression(quantity))
  40.  
  41. if __name__ == '__main__':
  42. cli.interface.cli()
Advertisement
Add Comment
Please, Sign In to add comment