Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ python3
- Python 3.2.3 (default, Sep 25 2013, 18:25:56)
- [GCC 4.6.3] on linux2
- Type "help", "copyright", "credits" or "license" for more information.
- >>> import numpy
- >>> a = numpy.arange(10)
- >>> numpy.getbuffer(a)
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- AttributeError: 'module' object has no attribute 'getbuffer'
- >>> import numpy
- >>> a = numpy.arange(10)
- >>> memoryview(a)
- <memory at 0xb60ae094>
- >>> m = _
- >>> m[0] = 9
- >>> a
- array([9, 1, 2, 3, 4, 5, 6, 7, 8, 9])
- setup = '''import numpy as np; x = np.random.random(n).reshape(n//10, -1)'''
- globals: {'n': 100}, tested 1e+06 times
- time (s) speedup methods
- 0 0.163005 6.03x x.tobytes()
- 1 0.491887 2.00x x.data.tobytes()
- 2 0.598286 1.64x memoryview(x).tobytes()
- 3 0.964653 1.02x bytes(x.data)
- 4 0.982743 bytes(memoryview(x))
- globals: {'n': 1000}, tested 1e+06 times
- time (s) speedup methods
- 0 0.378260 3.21x x.tobytes()
- 1 0.708204 1.71x x.data.tobytes()
- 2 0.827941 1.47x memoryview(x).tobytes()
- 3 1.189048 1.02x bytes(x.data)
- 4 1.213423 bytes(memoryview(x))
- globals: {'n': 10000}, tested 1e+06 times
- time (s) speedup methods
- 0 3.393949 1.34x x.tobytes()
- 1 3.739483 1.22x x.data.tobytes()
- 2 4.033783 1.13x memoryview(x).tobytes()
- 3 4.469730 1.02x bytes(x.data)
- 4 4.543620 bytes(memoryview(x))
Add Comment
Please, Sign In to add comment