/test/speed/understand_dynamic_index.py
http://pickled-object-database.googlecode.com/ · Python · 137 lines · 90 code · 47 blank · 0 comment · 25 complexity · 338818d9c64eaa1c6d2feb35bfb2712d MD5 · raw file
- import ajc
- import pod
- import time
- import random
-
- class PersonNoTyped(pod.Object):
- POD_DYNAMIC_INDEX = True
-
- 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)
- phrase = pod.typed.String(index = False)
-
- class PersonTypedWithIndex(pod.Object):
- age = pod.typed.Int(index = True)
- name = pod.typed.String(index = True)
- weight = pod.typed.Float(index = True)
- phrase = pod.typed.String(index = True)
-
-
-
- db = pod.Db(file = 'mypod100000.sqlite3', remove = False, clear = False, very_chatty = False)
-
-
- ajc.util.time_start(msg = 'Check fid speed')
- print len([row for row in PersonTyped.execute('SELECT age FROM cls_table WHERE age = 25')])
- ajc.util.time_stop()
-
- ajc.util.time_start(msg = 'Check fid speed')
- print len([row for row in PersonNoTyped.execute('SELECT str FROM cls_table_kvdict WHERE fid = 94340')])
- ajc.util.time_stop()
-
- ajc.util.time_start(msg = 'Check fid speed')
- print len([row for row in PersonNoTyped.execute('SELECT str FROM cls_table_kvdict WHERE fid = 9440 and key = "name"')])
- ajc.util.time_stop()
-
- ajc.util.time_start(msg = 'Check fid speed')
- print len([row for row in PersonTyped.execute('SELECT age FROM cls_table WHERE age = 25')])
- ajc.util.time_stop()
-
- exit()
-
- ajc.util.time_start(msg = 'PersonNoTyped org Query')
- print len([peep for peep in PersonNoTyped.age < 25])
- ajc.util.time_stop()
-
- ajc.util.time_start(msg = 'PersonNoTypedWithIndex org Query')
- print len([peep for peep in PersonNoTypedWithIndex.age < 25])
- ajc.util.time_stop()
-
- ajc.util.time_start(msg = 'PersonTyped org query')
- print len([peep for peep in PersonTyped.age < 25])
- ajc.util.time_stop()
-
- ajc.util.time_start(msg = 'PersonTypedWithIndex org query')
- print len([peep for peep in PersonTypedWithIndex.age < 25])
- ajc.util.time_stop()
-
- ajc.util.time_start(msg = 'Fixed PersonNoTypedWithIndex query')
- print len([row for row in PersonNoTypedWithIndex.execute('SELECT fid FROM cls_table_kvdict WHERE key="age" AND num > -1e100 AND num < 25')])
- ajc.util.time_stop()
-
- ajc.util.time_start(msg = 'Try equals PersonNoTypedWithIndex query')
- print len([row for row in PersonNoTypedWithIndex.execute('SELECT fid FROM cls_table_kvdict WHERE key="age" AND num = 1')])
- ajc.util.time_stop()
-
-
-
-
-
- ajc.util.time_start(msg = 'PersonTyped str query')
- print len([row for row in PersonTyped.execute('SELECT id FROM cls_table WHERE name="Stanley25"')])
- ajc.util.time_stop()
-
- ajc.util.time_start(msg = 'PersonTypedWithIndex str query')
- print len([row for row in PersonTypedWithIndex.execute('SELECT id FROM cls_table WHERE name="Stanley25"')])
- ajc.util.time_stop()
-
- ajc.util.time_start(msg = 'PersonTypedWithIndex LIKE str query')
- print len([row for row in PersonTypedWithIndex.execute('SELECT id FROM cls_table WHERE name LIKE "%ley25"')])
- ajc.util.time_stop()
-
- ajc.util.time_start(msg = 'PersonTypedWithIndex substr query')
- print len([row for row in PersonTypedWithIndex.execute('SELECT id FROM cls_table WHERE substr(name,-4) == "ey25"')])
- ajc.util.time_stop()
-
- ajc.util.time_start(msg = 'PersonTypedWithIndex double substr query')
- print len([row for row in PersonTypedWithIndex.execute('SELECT id FROM cls_table WHERE substr(name,1,1) == "S" AND substr(name,-4) == "ey25"')])
- ajc.util.time_stop()
-
-
-
-
-
-
-
- ajc.util.time_start(msg = 'PersonNoTyped str query')
- print len([row for row in PersonNoTyped.execute('SELECT fid FROM cls_table_kvdict WHERE key="name" AND str="Stanley25"')])
- ajc.util.time_stop()
-
- ajc.util.time_start(msg = 'PersonNoTypedWithIndex str query')
- print len([row for row in PersonNoTypedWithIndex.execute('SELECT fid FROM cls_table_kvdict WHERE key="name" AND str="Stanley25"')])
- ajc.util.time_stop()
-
- ajc.util.time_start(msg = 'PersonNoTypedWithIndex LIKE str query')
- print len([row for row in PersonNoTypedWithIndex.execute('SELECT fid FROM cls_table_kvdict WHERE key="name" AND str LIKE "%ley25"')])
- ajc.util.time_stop()
-
- ajc.util.time_start(msg = 'PersonNoTypedWithIndex substr query')
- print len([row for row in PersonNoTypedWithIndex.execute('SELECT fid FROM cls_table_kvdict WHERE key="name" AND substr(str,-4) == "ey25"')])
- ajc.util.time_stop()
-
- ajc.util.time_start(msg = 'PersonNoTypedWithIndex double substr query')
- print len([row for row in PersonNoTypedWithIndex.execute('SELECT fid FROM cls_table_kvdict WHERE key="name" AND substr(str,1,1) == "S" AND substr(str,-4) == "ey25"')])
- ajc.util.time_stop()
-
-
-
-
-
- if False:
- for peep in PersonTypedWithIndex:
- peep.age = random.randrange(1,100000)
-
- for peep in PersonNoTypedWithIndex:
- peep.age = random.randrange(1,100000)
-
- db.commit()
-
- if False:
- for peep in PersonNoTypedWithIndex:
- peep.weight = None
- db.commit()