10K_children.py 769 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env python
  2. import sys
  3. import arrow
  4. import requests
  5. default_n = 10000
  6. sys.stdout.write('How many children? [{}] >'.format(default_n))
  7. choice = input().lower()
  8. n = choice or default_n
  9. # Generate 10,000 children of root node.
  10. requests.put('http://localhost:8000/ldp/pomegranate')
  11. start = arrow.utcnow()
  12. ckpt = start
  13. print('Inserting {} children.'.format(n))
  14. for i in range(1, n):
  15. requests.post('http://localhost:8000/ldp/pomegranate')
  16. if i % 100 == 0:
  17. now = arrow.utcnow()
  18. tdelta = now - ckpt
  19. ckpt = now
  20. print('Record: {}\tTime elapsed: {}'.format(i, tdelta))
  21. tdelta = arrow.utcnow() - start
  22. print('Total elapsed time: {}'.format(tdelta))
  23. print('Average time per resource: {}'.format(tdelta.total_seconds()/n))