[Patches] [ python-Patches-1493701 ] Performance enhancements for struct module

SourceForge.net noreply at sourceforge.net
Tue May 23 20:48:09 CEST 2006


Patches item #1493701, was opened at 2006-05-23 12:47
Message generated for change (Comment added) made by etrepum
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1493701&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Performance
Group: Python 2.5
>Status: Closed
>Resolution: Accepted
Priority: 5
Submitted By: Bob Ippolito (etrepum)
>Assigned to: Bob Ippolito (etrepum)
Summary: Performance enhancements for struct module

Initial Comment:
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.

----------------------------------------------------------------------

>Comment By: Bob Ippolito (etrepum)
Date: 2006-05-23 14:48

Message:
Logged In: YES 
user_id=139309

Applied in revision 46134

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1493701&group_id=5470


More information about the Patches mailing list