/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

  1. import ajc
  2. import pod
  3. import time
  4. import random
  5. class PersonNoTyped(pod.Object):
  6. POD_DYNAMIC_INDEX = True
  7. class PersonNoTypedWithIndex(pod.Object):
  8. POD_DYNAMIC_INDEX = True
  9. class PersonTyped(pod.Object):
  10. age = pod.typed.Int(index = False)
  11. name = pod.typed.String(index = False)
  12. weight = pod.typed.Float(index = False)
  13. phrase = pod.typed.String(index = False)
  14. class PersonTypedWithIndex(pod.Object):
  15. age = pod.typed.Int(index = True)
  16. name = pod.typed.String(index = True)
  17. weight = pod.typed.Float(index = True)
  18. phrase = pod.typed.String(index = True)
  19. db = pod.Db(file = 'mypod100000.sqlite3', remove = False, clear = False, very_chatty = False)
  20. ajc.util.time_start(msg = 'Check fid speed')
  21. print len([row for row in PersonTyped.execute('SELECT age FROM cls_table WHERE age = 25')])
  22. ajc.util.time_stop()
  23. ajc.util.time_start(msg = 'Check fid speed')
  24. print len([row for row in PersonNoTyped.execute('SELECT str FROM cls_table_kvdict WHERE fid = 94340')])
  25. ajc.util.time_stop()
  26. ajc.util.time_start(msg = 'Check fid speed')
  27. print len([row for row in PersonNoTyped.execute('SELECT str FROM cls_table_kvdict WHERE fid = 9440 and key = "name"')])
  28. ajc.util.time_stop()
  29. ajc.util.time_start(msg = 'Check fid speed')
  30. print len([row for row in PersonTyped.execute('SELECT age FROM cls_table WHERE age = 25')])
  31. ajc.util.time_stop()
  32. exit()
  33. ajc.util.time_start(msg = 'PersonNoTyped org Query')
  34. print len([peep for peep in PersonNoTyped.age < 25])
  35. ajc.util.time_stop()
  36. ajc.util.time_start(msg = 'PersonNoTypedWithIndex org Query')
  37. print len([peep for peep in PersonNoTypedWithIndex.age < 25])
  38. ajc.util.time_stop()
  39. ajc.util.time_start(msg = 'PersonTyped org query')
  40. print len([peep for peep in PersonTyped.age < 25])
  41. ajc.util.time_stop()
  42. ajc.util.time_start(msg = 'PersonTypedWithIndex org query')
  43. print len([peep for peep in PersonTypedWithIndex.age < 25])
  44. ajc.util.time_stop()
  45. ajc.util.time_start(msg = 'Fixed PersonNoTypedWithIndex query')
  46. print len([row for row in PersonNoTypedWithIndex.execute('SELECT fid FROM cls_table_kvdict WHERE key="age" AND num > -1e100 AND num < 25')])
  47. ajc.util.time_stop()
  48. ajc.util.time_start(msg = 'Try equals PersonNoTypedWithIndex query')
  49. print len([row for row in PersonNoTypedWithIndex.execute('SELECT fid FROM cls_table_kvdict WHERE key="age" AND num = 1')])
  50. ajc.util.time_stop()
  51. ajc.util.time_start(msg = 'PersonTyped str query')
  52. print len([row for row in PersonTyped.execute('SELECT id FROM cls_table WHERE name="Stanley25"')])
  53. ajc.util.time_stop()
  54. ajc.util.time_start(msg = 'PersonTypedWithIndex str query')
  55. print len([row for row in PersonTypedWithIndex.execute('SELECT id FROM cls_table WHERE name="Stanley25"')])
  56. ajc.util.time_stop()
  57. ajc.util.time_start(msg = 'PersonTypedWithIndex LIKE str query')
  58. print len([row for row in PersonTypedWithIndex.execute('SELECT id FROM cls_table WHERE name LIKE "%ley25"')])
  59. ajc.util.time_stop()
  60. ajc.util.time_start(msg = 'PersonTypedWithIndex substr query')
  61. print len([row for row in PersonTypedWithIndex.execute('SELECT id FROM cls_table WHERE substr(name,-4) == "ey25"')])
  62. ajc.util.time_stop()
  63. ajc.util.time_start(msg = 'PersonTypedWithIndex double substr query')
  64. print len([row for row in PersonTypedWithIndex.execute('SELECT id FROM cls_table WHERE substr(name,1,1) == "S" AND substr(name,-4) == "ey25"')])
  65. ajc.util.time_stop()
  66. ajc.util.time_start(msg = 'PersonNoTyped str query')
  67. print len([row for row in PersonNoTyped.execute('SELECT fid FROM cls_table_kvdict WHERE key="name" AND str="Stanley25"')])
  68. ajc.util.time_stop()
  69. ajc.util.time_start(msg = 'PersonNoTypedWithIndex str query')
  70. print len([row for row in PersonNoTypedWithIndex.execute('SELECT fid FROM cls_table_kvdict WHERE key="name" AND str="Stanley25"')])
  71. ajc.util.time_stop()
  72. ajc.util.time_start(msg = 'PersonNoTypedWithIndex LIKE str query')
  73. print len([row for row in PersonNoTypedWithIndex.execute('SELECT fid FROM cls_table_kvdict WHERE key="name" AND str LIKE "%ley25"')])
  74. ajc.util.time_stop()
  75. ajc.util.time_start(msg = 'PersonNoTypedWithIndex substr query')
  76. print len([row for row in PersonNoTypedWithIndex.execute('SELECT fid FROM cls_table_kvdict WHERE key="name" AND substr(str,-4) == "ey25"')])
  77. ajc.util.time_stop()
  78. ajc.util.time_start(msg = 'PersonNoTypedWithIndex double substr query')
  79. 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"')])
  80. ajc.util.time_stop()
  81. if False:
  82. for peep in PersonTypedWithIndex:
  83. peep.age = random.randrange(1,100000)
  84. for peep in PersonNoTypedWithIndex:
  85. peep.age = random.randrange(1,100000)
  86. db.commit()
  87. if False:
  88. for peep in PersonNoTypedWithIndex:
  89. peep.weight = None
  90. db.commit()