[Patches] [ python-Patches-977553 ] Speed up EnumKey call

SourceForge.net noreply at sourceforge.net
Sun Feb 19 00:37:35 CET 2006


Patches item #977553, was opened at 2004-06-22 17:22
Message generated for change (Comment added) made by birkenfeld
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=977553&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: Windows
Group: Python 2.4
>Status: Closed
>Resolution: Accepted
Priority: 6
Submitted By: Garth Bushell (garth42)
Assigned to: Nobody/Anonymous (nobody)
Summary: Speed up EnumKey call

Initial Comment:
This patch removes the RegQueryInfoKey call and
replaces it with a call to EnumKeyEx. This greatly
speeds up this call. 

The script below times 

python 2.3              5531 89.7130000591
python 2.4 +patch   5531 0.0469999313354

start = time.time()
i = 0
try:
  while 1:
    _winreg.EnumKey(_winreg.HKEY_CLASSES_ROOT, i)
    i += 1
except WindowsError:
  pass
print i, time.time() - start


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

>Comment By: Georg Brandl (birkenfeld)
Date: 2006-02-19 00:37

Message:
Logged In: YES 
user_id=1188172

Cleaned up and committed in rev. 42475.

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

Comment By: Georg Brandl (birkenfeld)
Date: 2005-07-02 13:08

Message:
Logged In: YES 
user_id=1188172

Attached a revised patch following coding style and adding
additional error handling.

winreg-enumkey.diff

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

Comment By: Martin v. Löwis (loewis)
Date: 2005-03-03 09:08

Message:
Logged In: YES 
user_id=21627

garth42, can you please indicate whether you are willing to
work on the patch, and if so in what time frame?

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

Comment By: Alan McIntyre (alanmcintyre)
Date: 2005-02-27 17:59

Message:
Logged In: YES 
user_id=1115903

I think it's a good idea to get 16-bit Windows functions out
of Python per Microsoft's recommendation, especially when
doing so can also help performance.  

It looks like this patch still needs some cleanup and a test
or two.  If nobody else wants to do it I can probably finish
it up.

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

Comment By: Martin v. Löwis (loewis)
Date: 2004-07-26 14:31

Message:
Logged In: YES 
user_id=21627

Also, please follow the Python style guide for C code, PEP
7. In particular:
- use tabs for indentation, with a tab being worth 8 spaces
- omit spaces after opening and before closing parens
- put the opening brace of a code block on the same line as
the keyword


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

Comment By: Garth Bushell (garth42)
Date: 2004-07-14 18:12

Message:
Logged In: YES 
user_id=45280

mmangino: 

Yes you're correct it should be 256 in both cases. Doh! I'll
attach a new patch in a while. but It's easy to mmodify the
patch and up the linit to 256

theller:

The advantage of the latter is it returns the Length of the
string returned so we can pass it straight back to the
string creation funtion in python without a strlen.

also the SDK says this....

Note  This function is provided only for compatibility with
16-bit versions of Windows. Applications should use the
RegEnumKeyEx function.



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

Comment By: Thomas Heller (theller)
Date: 2004-07-14 17:54

Message:
Logged In: YES 
user_id=11105

I'm curious: Why did you replace RegEnumKey with
RegEnumKeyEx? Are there any advantages of the latter?

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

Comment By: Mike Mangino (mmangino)
Date: 2004-07-14 16:12

Message:
Logged In: YES 
user_id=74879

This looks good to me, but I think the buffer size is off by
one. I read the SDK to say tha they key can be 255
characters. That means you need to allocate 256 characters
to allow for the null terminator. Could you create a test
case for a max length registry key?

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

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


More information about the Patches mailing list