PageRenderTime 39ms CodeModel.GetById 28ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/test/speed/run.py

http://pickled-object-database.googlecode.com/
Python | 30 lines | 24 code | 5 blank | 1 comment | 8 complexity | 94c9b0a68bef68e64482279738a06196 MD5 | raw file
 1import time 
 2import pod
 3import random
 4
 5def run(test_list, number_of_records, clear_cache, n = 10):
 6    the_times = {}
 7    
 8    rtest = []
 9    nlist = range(len(test_list))
10    for i in range(n):
11        random.shuffle(nlist)
12        for j in nlist:
13            rtest.append(test_list[j])
14    
15    for db,fn in rtest:
16        db.commit(clear_cache = clear_cache)
17        fn(number_of_records = 1)
18        db.commit(clear_cache = clear_cache)
19        time.sleep(1)
20        time_start = 1000*time.time()    
21        fn(number_of_records = number_of_records-1)
22        db.commit(clear_cache = False)
23        time_end = int(1000*time.time()-time_start)
24        the_times[fn.__name__] = the_times.setdefault(fn.__name__, 0) + time_end
25        #print "\tTime for '" + fn.__name__ + "': " + str(time_end) + " milliseconds." 
26        db.commit(clear_cache = clear_cache)
27        
28    for key,value in the_times.iteritems():
29        print ";\tTime for '" +  key + "': " + str(value/n) + "ms"  
30