PageRenderTime 344ms CodeModel.GetById 141ms app.highlight 12ms RepoModel.GetById 189ms app.codeStats 1ms

/test/speed/test_query.py

http://pickled-object-database.googlecode.com/
Python | 89 lines | 62 code | 26 blank | 1 comment | 16 complexity | ffcbb865b62c5685d3debe3aa3a58299 MD5 | raw file
 1import time
 2import run
 3import sys
 4
 5org_modules = set(sys.modules.copy().keys())
 6
 7for number in [10000, 100000, 1000000]:
 8    
 9    new_modules = set(sys.modules.copy().keys()) - org_modules
10    for key in new_modules:
11        del sys.modules[key]
12        
13    import pod
14
15    class PersonNoTyped(pod.Object):
16        POD_DYNAMIC_INDEX = False
17    
18    class PersonNoTypedWithIndex(pod.Object):
19        POD_DYNAMIC_INDEX = True
20    
21    class PersonTyped(pod.Object):
22        age    = pod.typed.Int(index = False)
23        name   = pod.typed.String(index = False)
24        weight = pod.typed.Float(index = False)
25        
26    class PersonTypedWithIndex(pod.Object):
27        age    = pod.typed.Int(index = True)
28        name   = pod.typed.String(index = True)
29        weight = pod.typed.Float(index = True)
30        
31    pod.db.current.global_db = None
32    db_rwni = pod.Db(file = './pods/mypod_' + str(number) + '_rwni.sqlite3', attach = [], remove = False, clear = False, very_chatty = False)
33    db_rwwi = pod.Db(file = './pods/mypod_' + str(number) + '_rwwi.sqlite3', attach = [], remove = False, clear = False, very_chatty = False)
34    db_ntni = pod.Db(file = './pods/mypod_' + str(number) + '_ntni.sqlite3', attach = [PersonNoTyped], remove = False, clear = False, very_chatty = False)
35    db_ntwi = pod.Db(file = './pods/mypod_' + str(number) + '_ntwi.sqlite3', attach = [PersonNoTypedWithIndex], remove = False, clear = False, very_chatty = False)
36    db_wtni = pod.Db(file = './pods/mypod_' + str(number) + '_wtni.sqlite3', attach = [PersonTyped], remove = False, clear = False, very_chatty = False)
37    db_wtwi = pod.Db(file = './pods/mypod_' + str(number) + '_wtwi.sqlite3', attach = [PersonTypedWithIndex], remove = False, clear = False, very_chatty = False)
38
39    """ The tests """
40    def sql_query_raw(number_of_records):
41        
42        db_rwni.cursor.execute("SELECT id,name FROM raw WHERE age < ?", (1,))
43        for row in db_rwni.cursor: 
44            id,name = row[0],row[1]
45
46    def sql_query_raw_with_index(number_of_records):
47        
48        db_rwwi.cursor.execute("SELECT id,name FROM raw_with_index WHERE age < ?", (1,))
49        for row in db_rwwi.cursor: 
50            id,name = row[0],row[1]
51               
52    def pod_query_no_typed(number_of_records):
53    
54        for peep in PersonNoTyped.where.age < 1:
55            peep.name 
56   
57    def pod_query_no_typed_with_index(number_of_records):
58    
59        for peep in PersonNoTypedWithIndex.where.age < 1:
60            peep.name 
61            
62    def pod_query_typed(number_of_records):
63    
64        for peep in pod.Query(select = PersonTyped.name, where = PersonTyped.age < 1):
65            peep.name 
66    
67    def pod_query_typed_with_index(number_of_records):
68    
69        for peep in pod.Query(select = PersonTypedWithIndex.name, where = PersonTypedWithIndex.age < 1):
70            peep.name 
71
72    print '; Query on ' + str(number) + ' records'
73    
74    test_list = [             
75                 (db_rwni, sql_query_raw),
76                 (db_rwwi, sql_query_raw_with_index),
77                 (db_ntni, pod_query_no_typed),
78                 (db_ntwi, pod_query_no_typed_with_index),
79                 (db_wtni, pod_query_typed),
80                 (db_wtwi, pod_query_typed_with_index),
81                 ]
82    
83    test_list = test_list
84    
85    run.run(test_list = test_list,
86            number_of_records = number, 
87            clear_cache = True, 
88            n = 1)
89