/test/speed/test_query.py
http://pickled-object-database.googlecode.com/ · Python · 89 lines · 62 code · 26 blank · 1 comment · 8 complexity · ffcbb865b62c5685d3debe3aa3a58299 MD5 · raw file
- import time
- import run
- import sys
-
- org_modules = set(sys.modules.copy().keys())
-
- for number in [10000, 100000, 1000000]:
-
- new_modules = set(sys.modules.copy().keys()) - org_modules
- for key in new_modules:
- del sys.modules[key]
-
- import pod
-
- class PersonNoTyped(pod.Object):
- POD_DYNAMIC_INDEX = False
-
- class PersonNoTypedWithIndex(pod.Object):
- POD_DYNAMIC_INDEX = True
-
- class PersonTyped(pod.Object):
- age = pod.typed.Int(index = False)
- name = pod.typed.String(index = False)
- weight = pod.typed.Float(index = False)
-
- class PersonTypedWithIndex(pod.Object):
- age = pod.typed.Int(index = True)
- name = pod.typed.String(index = True)
- weight = pod.typed.Float(index = True)
-
- pod.db.current.global_db = None
- db_rwni = pod.Db(file = './pods/mypod_' + str(number) + '_rwni.sqlite3', attach = [], remove = False, clear = False, very_chatty = False)
- db_rwwi = pod.Db(file = './pods/mypod_' + str(number) + '_rwwi.sqlite3', attach = [], remove = False, clear = False, very_chatty = False)
- db_ntni = pod.Db(file = './pods/mypod_' + str(number) + '_ntni.sqlite3', attach = [PersonNoTyped], remove = False, clear = False, very_chatty = False)
- db_ntwi = pod.Db(file = './pods/mypod_' + str(number) + '_ntwi.sqlite3', attach = [PersonNoTypedWithIndex], remove = False, clear = False, very_chatty = False)
- db_wtni = pod.Db(file = './pods/mypod_' + str(number) + '_wtni.sqlite3', attach = [PersonTyped], remove = False, clear = False, very_chatty = False)
- db_wtwi = pod.Db(file = './pods/mypod_' + str(number) + '_wtwi.sqlite3', attach = [PersonTypedWithIndex], remove = False, clear = False, very_chatty = False)
-
- """ The tests """
- def sql_query_raw(number_of_records):
-
- db_rwni.cursor.execute("SELECT id,name FROM raw WHERE age < ?", (1,))
- for row in db_rwni.cursor:
- id,name = row[0],row[1]
-
- def sql_query_raw_with_index(number_of_records):
-
- db_rwwi.cursor.execute("SELECT id,name FROM raw_with_index WHERE age < ?", (1,))
- for row in db_rwwi.cursor:
- id,name = row[0],row[1]
-
- def pod_query_no_typed(number_of_records):
-
- for peep in PersonNoTyped.where.age < 1:
- peep.name
-
- def pod_query_no_typed_with_index(number_of_records):
-
- for peep in PersonNoTypedWithIndex.where.age < 1:
- peep.name
-
- def pod_query_typed(number_of_records):
-
- for peep in pod.Query(select = PersonTyped.name, where = PersonTyped.age < 1):
- peep.name
-
- def pod_query_typed_with_index(number_of_records):
-
- for peep in pod.Query(select = PersonTypedWithIndex.name, where = PersonTypedWithIndex.age < 1):
- peep.name
-
- print '; Query on ' + str(number) + ' records'
-
- test_list = [
- (db_rwni, sql_query_raw),
- (db_rwwi, sql_query_raw_with_index),
- (db_ntni, pod_query_no_typed),
- (db_ntwi, pod_query_no_typed_with_index),
- (db_wtni, pod_query_typed),
- (db_wtwi, pod_query_typed_with_index),
- ]
-
- test_list = test_list
-
- run.run(test_list = test_list,
- number_of_records = number,
- clear_cache = True,
- n = 1)