This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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:27methanesetrecipients: + methane
2016-08-07 19:22:27methanesetmessageid: <1470597747.43.0.480552843757.issue27704@psf.upfronthosting.co.za>
2016-08-07 19:22:27methanelinkissue27704 messages
2016-08-07 19:22:27methanecreate