fts3speed.tcl 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #--------------------------------------------------------------------------
  2. # This script contains several sub-programs used to test FTS3/FTS4
  3. # performance. It does not run the queries directly, but generates SQL
  4. # scripts that can be run using the shell tool.
  5. #
  6. # The following cases are tested:
  7. #
  8. # 1. Inserting documents into an FTS3 table.
  9. # 2. Optimizing an FTS3 table (i.e. "INSERT INTO t1 VALUES('optimize')").
  10. # 3. Deleting documents from an FTS3 table.
  11. # 4. Querying FTS3 tables.
  12. #
  13. # Number of tokens in vocabulary. And number of tokens in each document.
  14. #
  15. set VOCAB_SIZE 2000
  16. set DOC_SIZE 100
  17. set NUM_INSERTS 100000
  18. set NUM_SELECTS 1000
  19. # Force everything in this script to be deterministic.
  20. #
  21. expr {srand(0)}
  22. proc usage {} {
  23. puts stderr "Usage: $::argv0 <rows> <selects>"
  24. exit -1
  25. }
  26. proc sql {sql} {
  27. puts $::fd $sql
  28. }
  29. # Return a list of $nWord randomly generated tokens each between 2 and 10
  30. # characters in length.
  31. #
  32. proc build_vocab {nWord} {
  33. set ret [list]
  34. set chars [list a b c d e f g h i j k l m n o p q r s t u v w x y z]
  35. for {set i 0} {$i<$nWord} {incr i} {
  36. set len [expr {int((rand()*9.0)+2)}]
  37. set term ""
  38. for {set j 0} {$j<$len} {incr j} {
  39. append term [lindex $chars [expr {int(rand()*[llength $chars])}]]
  40. }
  41. lappend ret $term
  42. }
  43. set ret
  44. }
  45. proc select_term {} {
  46. set n [llength $::vocab]
  47. set t [expr int(rand()*$n*3)]
  48. if {$t>=2*$n} { set t [expr {($t-2*$n)/100}] }
  49. if {$t>=$n} { set t [expr {($t-$n)/10}] }
  50. lindex $::vocab $t
  51. }
  52. proc select_doc {nTerm} {
  53. set ret [list]
  54. for {set i 0} {$i<$nTerm} {incr i} {
  55. lappend ret [select_term]
  56. }
  57. set ret
  58. }
  59. proc test_1 {nInsert} {
  60. sql "PRAGMA synchronous = OFF;"
  61. sql "DROP TABLE IF EXISTS t1;"
  62. sql "CREATE VIRTUAL TABLE t1 USING fts4;"
  63. for {set i 0} {$i < $nInsert} {incr i} {
  64. set doc [select_doc $::DOC_SIZE]
  65. sql "INSERT INTO t1 VALUES('$doc');"
  66. }
  67. }
  68. proc test_2 {} {
  69. sql "INSERT INTO t1(t1) VALUES('optimize');"
  70. }
  71. proc test_3 {nSelect} {
  72. for {set i 0} {$i < $nSelect} {incr i} {
  73. sql "SELECT count(*) FROM t1 WHERE t1 MATCH '[select_term]';"
  74. }
  75. }
  76. proc test_4 {nSelect} {
  77. for {set i 0} {$i < $nSelect} {incr i} {
  78. sql "SELECT count(*) FROM t1 WHERE t1 MATCH '[select_term] [select_term]';"
  79. }
  80. }
  81. if {[llength $argv]!=0} usage
  82. set ::vocab [build_vocab $::VOCAB_SIZE]
  83. set ::fd [open fts3speed_insert.sql w]
  84. test_1 $NUM_INSERTS
  85. close $::fd
  86. set ::fd [open fts3speed_select.sql w]
  87. test_3 $NUM_SELECTS
  88. close $::fd
  89. set ::fd [open fts3speed_select2.sql w]
  90. test_4 $NUM_SELECTS
  91. close $::fd
  92. set ::fd [open fts3speed_optimize.sql w]
  93. test_2
  94. close $::fd
  95. puts "Success. Created files:"
  96. puts " fts3speed_insert.sql"
  97. puts " fts3speed_select.sql"
  98. puts " fts3speed_select2.sql"
  99. puts " fts3speed_optimize.sql"