Double checked Python benchmark script

Michael Ströder michael at stroeder.com
Tue Jun 24 16:41:08 CEST 2003


Ed,

I wrote my own test script (attached). It's less complex to read but more 
flexible (through LDAP URL as parameter). Please review.

Usage: pref_test.py <LDAP URL> <number of tests>

Grab whole sub-tree 100 times (no server-side limit or logging, ~500 entries):

$ python perf_test.py "ldap://localhost:1390/dc=stroeder,dc=de?*?sub" 100
Opening connection each time: 20.4206629992
Reusing connection: 16.9708769321
Using ldapsearch: 6.0001270771

I'd appreciate if anyone with C knowledge could review what is done in 
ldap_result() (LDAPObject.c) and LDAPmessage_to_python() (message.c).

Ciao, Michael.

--------------------------------- snip ---------------------------------
#!/usr/bin/python

import sys,os,time,ldap

from ldap.ldapobject import LDAPObject
from ldapurl import LDAPUrl

try:
   ldap_url = LDAPUrl(sys.argv[1])
   num_tests = int(sys.argv[2])
except IndexError:
   print 'Usage: pref_test.py <LDAP URL> <number of tests>'
   sys.exit(1)

iter = num_tests
start_time = time.time()

while iter:

   l = LDAPObject(ldap_url.initializeUrl(),trace_level=0)
   l.protocol_version = 3
   l.simple_bind_s(ldap_url.who or '',ldap_url.cred or '')
   l.search_s(
     ldap_url.dn,
     ldap_url.scope or ldap.SCOPE_BASE,
     ldap_url.filterstr or '(objectClass=*)',
     ldap_url.attrs or ['*']
   )
   l.unbind_s()
   del l

   iter -= 1

end_time = time.time()
print 'Opening connection each time:',end_time-start_time


iter = num_tests
start_time = time.time()

l = LDAPObject(ldap_url.initializeUrl(),trace_level=0)
l.protocol_version = 3
l.simple_bind_s(ldap_url.who or '',ldap_url.cred or '')

while iter:

   l.search_s(
     ldap_url.dn,
     ldap_url.scope or ldap.SCOPE_BASE,
     ldap_url.filterstr or '(objectClass=*)',
     ldap_url.attrs or ['*']
   )

   iter -= 1

end_time = time.time()
l.unbind_s()
del l
print 'Reusing connection:',end_time-start_time


iter = num_tests
start_time = time.time()

while iter:

   os.system('ldapsearch -x -H "%s" -b "%s" -s %s "%s" %s > /dev/null' % (
     ldap_url.initializeUrl(),
     ldap_url.dn,
     {0:'base',1:'one',2:'sub'}[ldap_url.scope or ldap.SCOPE_BASE],
     ldap_url.filterstr or '(objectClass=*)',
     ' '.join(ldap_url.attrs or [])
   ))

   iter -= 1

end_time = time.time()
print 'Using ldapsearch:',end_time-start_time






More information about the python-ldap mailing list