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.

classification
Title: HMAC can get a 6x performance increase easily
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: akuchling Nosy List: akuchling, bmaurer
Priority: normal Keywords:

Created on 2006-12-18 23:12 by bmaurer, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
py.patch bmaurer, 2006-12-18 23:12 patch
Messages (3)
msg30827 - (view) Author: Ben Maurer (bmaurer) Date: 2006-12-18 23:12
The attached patch increases the performance of HMAC by a factor of 6. It does so by avoiding useing join/map in the strxor and using a lookup table. It would be faster just to do xor at the string level, but it's not clear that can be done without help from C.
msg30828 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2006-12-19 14:16
Thanks for your patch; I've modified it to remove _strxor() completely and applied the change as rev. 53065.  

When I tried a trivial benchmark, the speed improvement wasn't anywhere near 6X, and was more like 7%.  The patch is still worth applying because it also simplifies the code.
msg30829 - (view) Author: Ben Maurer (bmaurer) Date: 2006-12-19 14:58
The performance increase is if you call hmac.new a lot. I did a benchmark on a relatively small amount of cleartext (50 bytes). This was actually something I needed to use.

One thing I found -- reusing teh same hmac option helps *ALOT* the hmac docs don't make it clear how much this will help.
History
Date User Action Args
2022-04-11 14:56:21adminsetgithub: 44359
2006-12-18 23:12:40bmaurercreate