numpy_delete_vs_view.py 833 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. __author__ = "Christian Heider Nielsen"
  4. __doc__ = r"""
  5. Created on 03/04/2020
  6. """
  7. import time
  8. import numpy
  9. def test_perf_delete_vs_view():
  10. samples = 10
  11. for _ in range(samples):
  12. a = numpy.zeros((1000, 1000))
  13. s1 = time.time()
  14. b = a[1:]
  15. s2 = time.time()
  16. c = numpy.delete(a, 0, 0)
  17. s3 = time.time()
  18. print(f"view: {s2 - s1}")
  19. print(f"delete: {s3 - s2}")
  20. def test_perf_delete_vs_view2():
  21. samples = 10
  22. for _ in range(samples):
  23. a = numpy.zeros((1000, 1000))
  24. s1 = time.time()
  25. c = numpy.delete(a, 0, 0)
  26. s2 = time.time()
  27. b = a[1:]
  28. s3 = time.time()
  29. print(f"delete: {s2 - s1}")
  30. print(f"view: {s3 - s2}")
  31. # assert b == c