test_performance.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import json
  2. from timeit import default_timer as timer
  3. from django.test import TestCase
  4. class PerfTestCase(TestCase):
  5. def xtest_perf(self):
  6. data = json.dumps({"foo": "barrrrrr", "bar": 15544325, "lol": ["a", "c", "b"]})
  7. times = 10000
  8. url = "/api/echo/"
  9. self.client.post(url, data, content_type="application/json")
  10. print("ninja")
  11. start = timer()
  12. for _ in range(times):
  13. self.client.post(url, data, content_type="application/json")
  14. end = timer()
  15. print(end - start)
  16. print("view")
  17. url = "/api/echo_view/"
  18. self.client.post(url, data, content_type="application/json")
  19. start = timer()
  20. for _ in range(times):
  21. self.client.post(url, data, content_type="application/json")
  22. end = timer()
  23. print(end - start)
  24. print("DRF view")
  25. url = "/api/echo_class/"
  26. self.client.post(url, data, content_type="application/json")
  27. start = timer()
  28. for _ in range(times):
  29. self.client.post(url, data, content_type="application/json")
  30. end = timer()
  31. print(end - start)