Guest User

Untitled

a guest
Jun 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. $ python3
  2. Python 3.2.3 (default, Sep 25 2013, 18:25:56)
  3. [GCC 4.6.3] on linux2
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>> import numpy
  6. >>> a = numpy.arange(10)
  7. >>> numpy.getbuffer(a)
  8.  
  9. Traceback (most recent call last):
  10. File "<stdin>", line 1, in <module>
  11. AttributeError: 'module' object has no attribute 'getbuffer'
  12.  
  13. >>> import numpy
  14. >>> a = numpy.arange(10)
  15. >>> memoryview(a)
  16. <memory at 0xb60ae094>
  17. >>> m = _
  18. >>> m[0] = 9
  19. >>> a
  20. array([9, 1, 2, 3, 4, 5, 6, 7, 8, 9])
  21.  
  22. setup = '''import numpy as np; x = np.random.random(n).reshape(n//10, -1)'''
  23.  
  24. globals: {'n': 100}, tested 1e+06 times
  25.  
  26. time (s) speedup methods
  27. 0 0.163005 6.03x x.tobytes()
  28. 1 0.491887 2.00x x.data.tobytes()
  29. 2 0.598286 1.64x memoryview(x).tobytes()
  30. 3 0.964653 1.02x bytes(x.data)
  31. 4 0.982743 bytes(memoryview(x))
  32.  
  33.  
  34. globals: {'n': 1000}, tested 1e+06 times
  35.  
  36. time (s) speedup methods
  37. 0 0.378260 3.21x x.tobytes()
  38. 1 0.708204 1.71x x.data.tobytes()
  39. 2 0.827941 1.47x memoryview(x).tobytes()
  40. 3 1.189048 1.02x bytes(x.data)
  41. 4 1.213423 bytes(memoryview(x))
  42.  
  43.  
  44. globals: {'n': 10000}, tested 1e+06 times
  45.  
  46. time (s) speedup methods
  47. 0 3.393949 1.34x x.tobytes()
  48. 1 3.739483 1.22x x.data.tobytes()
  49. 2 4.033783 1.13x memoryview(x).tobytes()
  50. 3 4.469730 1.02x bytes(x.data)
  51. 4 4.543620 bytes(memoryview(x))
Add Comment
Please, Sign In to add comment