Message272130
| Author |
methane |
| Recipients |
methane |
| Date |
2016年08月07日.19:22:26 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1470597747.43.0.480552843757.issue27704@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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 |
|
History
|
|---|
| 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 |
|