New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize bytes.fromhex() and bytearray.fromhex() #69587
Comments
Attached patch optimizes bytes.fromhex() and bytearray.fromhex():
|
It's between 2 and 3.5x faster. It's 9% slower on short string (10 bytes for the output), but I consider that the speedup is more interesting than the slowdown on short strings. RMicrobenchmark: Common platform: Platform of campaign orig: Platform of campaign optim: -----------------------------------------+-------------+--------------- data = "AB" * 10; bytes.fromhex(data) | 167 ns (*) | 181 ns (+9%)
data = "AB" * 100; bytes.fromhex(data) | 621 ns (*) | 295 ns (-52%)
data = "AB" * 10**3; bytes.fromhex(data) | 5.15 us (*) | 1.65 us (-68%)
data = "AB" * 10**5; bytes.fromhex(data) | 500 us (*) | 147 us (-71%)
-----------------------------------------+-------------+ Total | 506 us (*) | 149 us (-70%) ---------------------------------------------------+-------------+--------------- data = "ABAB " * (10 // 2); bytes.fromhex(data) | 179 ns (*) | 186 ns
data = "ABAB " * (100 // 2); bytes.fromhex(data) | 659 ns (*) | 340 ns (-48%)
data = "ABAB " * (10**3 // 2); bytes.fromhex(data) | 5.48 us (*) | 2.19 us (-60%)
data = "ABAB " * (10**5 // 2); bytes.fromhex(data) | 529 us (*) | 194 us (-63%)
---------------------------------------------------+-------------+ Total | 536 us (*) | 196 us (-63%) ------------------------------------------+-------------+--------------- data = "AB " * 10; bytes.fromhex(data) | 180 ns (*) | 191 ns (+6%)
data = "AB " * 100; bytes.fromhex(data) | 710 ns (*) | 330 ns (-54%)
data = "AB " * 10**3; bytes.fromhex(data) | 5.77 us (*) | 1.99 us (-66%)
data = "AB " * 10**5; bytes.fromhex(data) | 559 us (*) | 177 us (-68%)
------------------------------------------+-------------+ Total | 565 us (*) | 179 us (-68%) ---------------+-------------+-------------- |
New changeset 55d207a637ff by Victor Stinner in branch 'default': |
New changeset 09e0533f3694 by Victor Stinner in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: