msg224671 - (view) |
Author: Kevin London (kevinlondon) * |
Date: 2014-08-04 02:05 |
Generating the byte representation of a UUID object can be a little faster by using binascii's unhexlify on the hex value of the UUID object. In my testing, I saw about a 5.5x speed increase with the attached changes. Here are a set of benchmarks that I ran, which are inspired by Wang Chun's benchmarks on http://bugs.python.org/issue5885: https://gist.github.com/kevinlondon/d3bb32d5a784f78731fa My times: kevin$ python uuid_benchmark.py 100000 Original Average: 8.049 microseconds Updated Average: 1.447 microseconds I re-ran all of the tests with the patched uuid module and they passed. Here's my patchcheck output as well: kevin$ make patchcheck ./python.exe ./Tools/scripts/patchcheck.py Getting the list of files that have been added/changed ... 1 file Fixing whitespace ... 0 files Fixing C file whitespace ... 0 files Fixing docs whitespace ... 0 files Docs modified ... NO Misc/ACKS updated ... NO Misc/NEWS updated ... NO configure regenerated ... not needed pyconfig.h.in regenerated ... not needed Thanks! |
|
|
msg224672 - (view) |
Author: Alex Gaynor (alex) *  |
Date: 2014-08-04 02:10 |
`self.int.to_bytes(16, byteorder='big')` looks to be even faster (about 3x on my machine) |
|
|
msg224673 - (view) |
Author: Alex Gaynor (alex) *  |
Date: 2014-08-04 02:10 |
What I said only applies to the Python3 version of this patch. Thanks for submitting this. |
|
|
msg224676 - (view) |
Author: Raymond Hettinger (rhettinger) *  |
Date: 2014-08-04 03:26 |
I also like the way the patch cleans-up the code. |
|
|
msg224697 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2014-08-04 08:09 |
If such changes are acceptable, here is a part of my large patch fo modernizing stdlib sources. Some microbenchmarks: $ ./python -m timeit -s "from uuid import NAMESPACE_DNS as u" -- "u.bytes" $ ./python -m timeit -s "from uuid import NAMESPACE_DNS as u" -- "u.bytes_le" $ ./python -m timeit -s "from uuid import UUID" -- "UUID(bytes_le=b'abcdefghijklmnop')" Before patch: 10000 loops, best of 3: 66.9 usec per loop 10000 loops, best of 3: 102 usec per loop 10000 loops, best of 3: 65.2 usec per loop After patch: 100000 loops, best of 3: 3.98 usec per loop 100000 loops, best of 3: 10.8 usec per loop 10000 loops, best of 3: 32.1 usec per loop |
|
|
msg224700 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2014-08-04 08:28 |
Just noticed that this patch also fixes a bug. When os.popen() fails in _ipconfig_getnode(), pipe is not set, and then NameError is raised in the finally branch. |
|
|
msg226498 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2014-09-06 17:36 |
Alex, Raymond, could you please make a review of my patch? |
|
|
msg226499 - (view) |
Author: Alex Gaynor (alex) *  |
Date: 2014-09-06 17:55 |
Patch looks good to me. |
|
|
msg226506 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2014-09-06 19:21 |
New changeset f7b5038d3102 by Serhiy Storchaka in branch 'default': Issue #22131: Modernized the code of the uuid module. http://hg.python.org/cpython/rev/f7b5038d3102 New changeset d8c6b15a2ae3 by Serhiy Storchaka in branch '2.7': Issue #22131: Fixed a bug in handling an error occured during reading from http://hg.python.org/cpython/rev/d8c6b15a2ae3 New changeset 8a61a287776d by Serhiy Storchaka in branch '3.4': Issue #22131: Fixed a bug in handling an error occured during reading from http://hg.python.org/cpython/rev/8a61a287776d |
|
|
msg226507 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2014-09-06 19:51 |
Thank you Alex. |
|
|