/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

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