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: Performance enhancements for struct module
Type: Stage:
Components: Interpreter Core Versions: Python 2.5
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: bob.ippolito Nosy List: bob.ippolito
Priority: normal Keywords: patch

Created on 2006-05-23 16:47 by bob.ippolito, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bippolito-newstruct-46117.diff bob.ippolito, 2006-05-23 16:47
Messages (3)
msg50335 - (view) Author: Bob Ippolito (bob.ippolito) * (Python committer) Date: 2006-05-23 16:47
This patch refactors the struct module to work like the re module: 
compile and cache the format in advance. This seems to yield at least a 
20% performance improvement on Mac OS X i386, depending on the 
length of the format string.

$ ./python-orig/_build/python.exe  -mtimeit -s "import struct; s = '\x00' 
* 16" "struct.unpack('>iId', s); struct.unpack('iId', s); struct.unpack('<iId', 
s)"
100000 loops, best of 3: 4.48 usec per loop

$ ./bippolito-newstruct/_build/python.exe  -mtimeit -s "import struct; s 
= '\x00' * 16" "struct.unpack('>iId', s); struct.unpack('iId', s); 
struct.unpack('<iId', s)"
100000 loops, best of 3: 3.54 usec per loop

It also adds a struct.Struct type, which is even faster to use than the pack/
unpack/calcsize functions since it doesn't need to look anything up in the 
cache.
msg50336 - (view) Author: Bob Ippolito (bob.ippolito) * (Python committer) Date: 2006-05-23 18:48
Logged In: YES 
user_id=139309

Applied in revision 46134
msg50337 - (view) Author: Bob Ippolito (bob.ippolito) * (Python committer) Date: 2006-05-24 09:27
Logged In: YES 
user_id=139309

Documentation for the new API in this patch is in:
http://python.org/sf/1494140
History
Date User Action Args
2022-04-11 14:56:17adminsetgithub: 43399
2006-05-23 16:47:34bob.ippolitocreate