test-sqlite-stmt-timing.nut 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. auto db = SQLite3(":memory:");
  2. db.exec_dml("create table test(id integer primary key, value text)");
  3. auto stmt_insert = db.prepare("insert into test(value) values(?)");
  4. auto max_loop = 10000;
  5. auto start_time;
  6. start_time = os.clock();
  7. for(auto i=0; i < max_loop; ++i)
  8. {
  9. stmt_insert.bind(1, "dad" + i);
  10. stmt_insert.step();
  11. stmt_insert.reset();
  12. }
  13. print("Time spent", os.clock() - start_time);
  14. db.exec_dml("delete from test");
  15. start_time = os.clock();
  16. for(auto i=0; i < max_loop; ++i)
  17. {
  18. {
  19. auto stmt_sr = db.stmt_scope_reset(stmt_insert);
  20. stmt_insert.bind(1, "dad" + i);
  21. stmt_insert.step();
  22. }
  23. }
  24. print("Time spent", os.clock() - start_time);
  25. db.exec_dml("delete from test");
  26. start_time = os.clock();
  27. for(auto i=0; i < max_loop; ++i)
  28. {
  29. stmt_insert.bind_exec("dad" + i);
  30. }
  31. print("Time spent", os.clock() - start_time);
  32. db.exec_dml("delete from test");
  33. start_time = os.clock();
  34. db.exec_dml("begin");
  35. for(auto i=0; i < max_loop; ++i)
  36. {
  37. stmt_insert.bind(1, "dad" + i);
  38. stmt_insert.step();
  39. stmt_insert.reset();
  40. }
  41. print("Time spent", os.clock() - start_time);
  42. db.exec_dml("delete from test");
  43. db.exec_dml("commit");
  44. start_time = os.clock();
  45. db.exec_dml("begin");
  46. for(auto i=0; i < max_loop; ++i)
  47. {
  48. {
  49. auto stmt_sr = db.stmt_scope_reset(stmt_insert);
  50. stmt_insert.bind(1, "dad" + i);
  51. stmt_insert.step();
  52. }
  53. }
  54. print("Time spent", os.clock() - start_time);
  55. db.exec_dml("delete from test");
  56. db.exec_dml("commit");
  57. start_time = os.clock();
  58. db.exec_dml("begin");
  59. for(auto i=0; i < max_loop; ++i)
  60. {
  61. stmt_insert.bind_exec("dad" + i);
  62. }
  63. print("Time spent", os.clock() - start_time);
  64. db.exec_dml("delete from test");
  65. db.exec_dml("commit");