1+ """ Usage: python benchmark.py ["database backend list" | backend1] [backend2]
2+
3+ Import the backend (anydbm, sqlite by default) and run some performance
4+ tests. Example:
5+
6+ test default anypy and sqlite backends
7+
8+ python benchmark.py
9+
10+ test mysql and sqlite backends
11+
12+ python benchmark.py mysql sqlite
13+
14+ or
15+
16+ python benchmark.py "mysql sqlite"
17+
18+ test all backends
19+
20+ python benchmark.py anydbm mysql postgresql sqlite
21+
22+
23+ """
124from __future__ import print_function
225import sys , os , time
326import importlib , signal , shutil
1740
1841from test .db_test_base import config
1942
43+ # global for the default signal hander so
44+ # my signal handler can reset before it raises signal.
2045int_sig_default_handler = None
2146
2247def setupSchema (db , module ):
@@ -38,26 +63,39 @@ def setupSchema(db, module):
3863def rm_db_on_signal (sig , frame ):
3964 print ("removing incomplete database %s due to interruption." %
4065 config .DATABASE )
66+
4167 shutil .rmtree (config .DATABASE )
68+
4269 signal .signal (signal .SIGINT , int_sig_default_handler )
70+ # re-raise the signal so the normal signal handling runs.
4371 signal .raise_signal (signal .SIGTERM )
4472
4573def main (backendname , time = time .time , numissues = 10 ):
4674 global int_sig_default_handler
75+
4776 try :
4877 backend = importlib .import_module ("roundup.backends.back_%s" %
4978 backendname )
5079 except ImportError :
80+ print ("Unable to import %s backend." % backendname )
5181 return
5282
5383 times = []
5484
5585 config .DATABASE = os .path .join ('_benchmark' , '%s-%s' % (backendname ,
5686 numissues ))
87+
88+ config .RDBMS_NAME = "rounduptest_%s" % numissues
89+
5790 if not os .path .exists (config .DATABASE ):
5891 int_sig_default_handler = signal .signal (signal .SIGINT , rm_db_on_signal )
5992 db = backend .Database (config , 'admin' )
6093 setupSchema (db , backend )
94+
95+ # if we are re-initializing, delete any existing db
96+ db .clear ()
97+ db .commit ()
98+
6199 # create a whole bunch of stuff
62100 db .user .create (** {'username' : 'admin' , 'roles' : 'Admin' })
63101 db .status .create (name = "unread" )
@@ -85,7 +123,7 @@ def main(backendname, time=time.time, numissues=10):
85123 db = backend .Database (config , 'admin' )
86124 setupSchema (db , backend )
87125
88- sys .stdout .write ('%7s : %-6d' % (backendname , numissues ))
126+ sys .stdout .write ('%10s : %-6d' % (backendname [: 10 ] , numissues ))
89127 sys .stdout .flush ()
90128
91129 times .append (('start' , time ()))
@@ -142,17 +180,35 @@ def main(backendname, time=time.time, numissues=10):
142180 sys .stdout .flush ()
143181
144182if __name__ == '__main__' :
183+ if len (sys .argv ) == 2 :
184+ test_databases = sys .argv [1 ].split ()
185+ elif len (sys .argv ) > 2 :
186+ test_databases = sys .argv [1 :]
187+ else :
188+ test_databases = ['anydbm' , 'sqlite' ]
189+
145190 # 0 1 2 3 4 5 6
146191 # 01234567890123456789012345678901234567890123456789012345678901234
147- print ('Test name fetch journl jprops lookup filter filtml TOTAL ' )
148- for name in 'anydbm sqlite' . split () :
192+ print ('Test name fetch journl jprops lookup filter filtml TOTAL ' )
193+ for name in test_databases :
149194 main (name )
150- for name in 'anydbm sqlite' . split () :
195+ for name in test_databases :
151196 main (name , numissues = 20 )
152- for name in 'anydbm sqlite' . split () :
197+ for name in test_databases :
153198 main (name , numissues = 100 )
199+
154200 # don't even bother benchmarking the dbm backends > 100!
155- for name in 'sqlite' .split ():
201+ try :
202+ test_databases .remove ('anydbm' )
203+ except ValueError :
204+ # anydbm not present; this is fine
205+ pass
206+
207+ for name in test_databases :
156208 main (name , numissues = 1000 )
157209
210+ for name in test_databases :
211+ main (name , numissues = 10000 )
212+
213+
158214# vim: set et sts=4 sw=4 :
0 commit comments