Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / sqlite / src / ext / fts3 / fts3speed.tcl
blob377cb196065699557b0a035a1e9d74808321187a
3 #--------------------------------------------------------------------------
4 # This script contains several sub-programs used to test FTS3/FTS4
5 # performance. It does not run the queries directly, but generates SQL
6 # scripts that can be run using the shell tool.
8 # The following cases are tested:
10 # 1. Inserting documents into an FTS3 table.
11 # 2. Optimizing an FTS3 table (i.e. "INSERT INTO t1 VALUES('optimize')").
12 # 3. Deleting documents from an FTS3 table.
13 # 4. Querying FTS3 tables.
16 # Number of tokens in vocabulary. And number of tokens in each document.
18 set VOCAB_SIZE 2000
19 set DOC_SIZE 100
21 set NUM_INSERTS 100000
22 set NUM_SELECTS 1000
24 # Force everything in this script to be deterministic.
26 expr {srand(0)}
28 proc usage {} {
29 puts stderr "Usage: $::argv0 <rows> <selects>"
30 exit -1
33 proc sql {sql} {
34 puts $::fd $sql
38 # Return a list of $nWord randomly generated tokens each between 2 and 10
39 # characters in length.
41 proc build_vocab {nWord} {
42 set ret [list]
43 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]
44 for {set i 0} {$i<$nWord} {incr i} {
45 set len [expr {int((rand()*9.0)+2)}]
46 set term ""
47 for {set j 0} {$j<$len} {incr j} {
48 append term [lindex $chars [expr {int(rand()*[llength $chars])}]]
50 lappend ret $term
52 set ret
55 proc select_term {} {
56 set n [llength $::vocab]
57 set t [expr int(rand()*$n*3)]
58 if {$t>=2*$n} { set t [expr {($t-2*$n)/100}] }
59 if {$t>=$n} { set t [expr {($t-$n)/10}] }
60 lindex $::vocab $t
63 proc select_doc {nTerm} {
64 set ret [list]
65 for {set i 0} {$i<$nTerm} {incr i} {
66 lappend ret [select_term]
68 set ret
71 proc test_1 {nInsert} {
72 sql "PRAGMA synchronous = OFF;"
73 sql "DROP TABLE IF EXISTS t1;"
74 sql "CREATE VIRTUAL TABLE t1 USING fts4;"
75 for {set i 0} {$i < $nInsert} {incr i} {
76 set doc [select_doc $::DOC_SIZE]
77 sql "INSERT INTO t1 VALUES('$doc');"
81 proc test_2 {} {
82 sql "INSERT INTO t1(t1) VALUES('optimize');"
85 proc test_3 {nSelect} {
86 for {set i 0} {$i < $nSelect} {incr i} {
87 sql "SELECT count(*) FROM t1 WHERE t1 MATCH '[select_term]';"
91 proc test_4 {nSelect} {
92 for {set i 0} {$i < $nSelect} {incr i} {
93 sql "SELECT count(*) FROM t1 WHERE t1 MATCH '[select_term] [select_term]';"
97 if {[llength $argv]!=0} usage
99 set ::vocab [build_vocab $::VOCAB_SIZE]
101 set ::fd [open fts3speed_insert.sql w]
102 test_1 $NUM_INSERTS
103 close $::fd
105 set ::fd [open fts3speed_select.sql w]
106 test_3 $NUM_SELECTS
107 close $::fd
109 set ::fd [open fts3speed_select2.sql w]
110 test_4 $NUM_SELECTS
111 close $::fd
113 set ::fd [open fts3speed_optimize.sql w]
114 test_2
115 close $::fd
117 puts "Success. Created files:"
118 puts " fts3speed_insert.sql"
119 puts " fts3speed_select.sql"
120 puts " fts3speed_select2.sql"
121 puts " fts3speed_optimize.sql"