Message272130
When bytes(x), bytes_new checks if x is integer via PyNumber_AsSize_t(x).
It cause TypeError internally.
When x is not an integer, especially bytearray or memoryview, the internal
exception cause significant overhead.
# HEAD
$ ./python -m timeit -s 'data=bytearray(b"xyz")' 'bytes(data)'
1000000 loops, best of 3: 0.696 usec per loop
$ ./python -m timeit -s 'data=bytearray(b"xyz")' 'bytes(data)'
1000000 loops, best of 3: 0.699 usec per loop
$ ./python -m timeit -s 'data=bytearray(b"xyz")' 'bytes(data)'
1000000 loops, best of 3: 0.701 usec per loop
# this patch
$ ./python -m timeit -s 'data=bytearray(b"xyz")' 'bytes(data)'
1000000 loops, best of 3: 0.265 usec per loop
$ ./python -m timeit -s 'data=bytearray(b"xyz")' 'bytes(data)'
1000000 loops, best of 3: 0.265 usec per loop
$ ./python -m timeit -s 'data=bytearray(b"xyz")' 'bytes(data)'
1000000 loops, best of 3: 0.267 usec per loop |
|
Date |
User |
Action |
Args |
2016-08-07 19:22:27 | methane | set | recipients:
+ methane |
2016-08-07 19:22:27 | methane | set | messageid: <1470597747.43.0.480552843757.issue27704@psf.upfronthosting.co.za> |
2016-08-07 19:22:27 | methane | link | issue27704 messages |
2016-08-07 19:22:27 | methane | create | |
|