diff options
Diffstat (limited to 'libraries/sqlite/unix/sqlite-3.5.1/test/speed1.test')
-rw-r--r-- | libraries/sqlite/unix/sqlite-3.5.1/test/speed1.test | 289 |
1 files changed, 289 insertions, 0 deletions
diff --git a/libraries/sqlite/unix/sqlite-3.5.1/test/speed1.test b/libraries/sqlite/unix/sqlite-3.5.1/test/speed1.test new file mode 100644 index 0000000..8b6ab9d --- /dev/null +++ b/libraries/sqlite/unix/sqlite-3.5.1/test/speed1.test | |||
@@ -0,0 +1,289 @@ | |||
1 | # 2006 November 23 | ||
2 | # | ||
3 | # The author disclaims copyright to this source code. In place of | ||
4 | # a legal notice, here is a blessing: | ||
5 | # | ||
6 | # May you do good and not evil. | ||
7 | # May you find forgiveness for yourself and forgive others. | ||
8 | # May you share freely, never taking more than you give. | ||
9 | # | ||
10 | #************************************************************************* | ||
11 | # This file implements regression tests for SQLite library. The | ||
12 | # focus of this script is measuring executing speed. | ||
13 | # | ||
14 | # $Id: speed1.test,v 1.5 2007/03/31 22:34:16 drh Exp $ | ||
15 | # | ||
16 | |||
17 | set testdir [file dirname $argv0] | ||
18 | source $testdir/tester.tcl | ||
19 | speed_trial_init speed1 | ||
20 | |||
21 | # Set a uniform random seed | ||
22 | expr srand(0) | ||
23 | |||
24 | set sqlout [open speed1.txt w] | ||
25 | proc tracesql {sql} { | ||
26 | puts $::sqlout $sql\; | ||
27 | } | ||
28 | #db trace tracesql | ||
29 | |||
30 | # The number_name procedure below converts its argment (an integer) | ||
31 | # into a string which is the English-language name for that number. | ||
32 | # | ||
33 | # Example: | ||
34 | # | ||
35 | # puts [number_name 123] -> "one hundred twenty three" | ||
36 | # | ||
37 | set ones {zero one two three four five six seven eight nine | ||
38 | ten eleven twelve thirteen fourteen fifteen sixteen seventeen | ||
39 | eighteen nineteen} | ||
40 | set tens {{} ten twenty thirty forty fifty sixty seventy eighty ninety} | ||
41 | proc number_name {n} { | ||
42 | if {$n>=1000} { | ||
43 | set txt "[number_name [expr {$n/1000}]] thousand" | ||
44 | set n [expr {$n%1000}] | ||
45 | } else { | ||
46 | set txt {} | ||
47 | } | ||
48 | if {$n>=100} { | ||
49 | append txt " [lindex $::ones [expr {$n/100}]] hundred" | ||
50 | set n [expr {$n%100}] | ||
51 | } | ||
52 | if {$n>=20} { | ||
53 | append txt " [lindex $::tens [expr {$n/10}]]" | ||
54 | set n [expr {$n%10}] | ||
55 | } | ||
56 | if {$n>0} { | ||
57 | append txt " [lindex $::ones $n]" | ||
58 | } | ||
59 | set txt [string trim $txt] | ||
60 | if {$txt==""} {set txt zero} | ||
61 | return $txt | ||
62 | } | ||
63 | |||
64 | # Create a database schema. | ||
65 | # | ||
66 | do_test speed1-1.0 { | ||
67 | execsql { | ||
68 | PRAGMA page_size=1024; | ||
69 | PRAGMA cache_size=8192; | ||
70 | PRAGMA locking_mode=EXCLUSIVE; | ||
71 | CREATE TABLE t1(a INTEGER, b INTEGER, c TEXT); | ||
72 | CREATE TABLE t2(a INTEGER, b INTEGER, c TEXT); | ||
73 | CREATE INDEX i2a ON t2(a); | ||
74 | CREATE INDEX i2b ON t2(b); | ||
75 | } | ||
76 | execsql { | ||
77 | SELECT name FROM sqlite_master ORDER BY 1; | ||
78 | } | ||
79 | } {i2a i2b t1 t2} | ||
80 | |||
81 | |||
82 | # 50000 INSERTs on an unindexed table | ||
83 | # | ||
84 | set sql {} | ||
85 | for {set i 1} {$i<=50000} {incr i} { | ||
86 | set r [expr {int(rand()*500000)}] | ||
87 | append sql "INSERT INTO t1 VALUES($i,$r,'[number_name $r]');\n" | ||
88 | } | ||
89 | db eval BEGIN | ||
90 | speed_trial speed1-insert1 50000 row $sql | ||
91 | db eval COMMIT | ||
92 | |||
93 | # 50000 INSERTs on an indexed table | ||
94 | # | ||
95 | set sql {} | ||
96 | for {set i 1} {$i<=50000} {incr i} { | ||
97 | set r [expr {int(rand()*500000)}] | ||
98 | append sql "INSERT INTO t2 VALUES($i,$r,'[number_name $r]');\n" | ||
99 | } | ||
100 | db eval BEGIN | ||
101 | speed_trial speed1-insert2 50000 row $sql | ||
102 | db eval COMMIT | ||
103 | |||
104 | |||
105 | |||
106 | # 50 SELECTs on an integer comparison. There is no index so | ||
107 | # a full table scan is required. | ||
108 | # | ||
109 | set sql {} | ||
110 | for {set i 0} {$i<50} {incr i} { | ||
111 | set lwr [expr {$i*100}] | ||
112 | set upr [expr {($i+10)*100}] | ||
113 | append sql "SELECT count(*), avg(b) FROM t1 WHERE b>=$lwr AND b<$upr;" | ||
114 | } | ||
115 | db eval BEGIN | ||
116 | speed_trial speed1-select1 [expr {50*50000}] row $sql | ||
117 | db eval COMMIT | ||
118 | |||
119 | # 50 SELECTs on an LIKE comparison. There is no index so a full | ||
120 | # table scan is required. | ||
121 | # | ||
122 | set sql {} | ||
123 | for {set i 0} {$i<50} {incr i} { | ||
124 | append sql \ | ||
125 | "SELECT count(*), avg(b) FROM t1 WHERE c LIKE '%[number_name $i]%';" | ||
126 | } | ||
127 | db eval BEGIN | ||
128 | speed_trial speed1-select2 [expr {50*50000}] row $sql | ||
129 | db eval COMMIT | ||
130 | |||
131 | # Create indices | ||
132 | # | ||
133 | db eval BEGIN | ||
134 | speed_trial speed1-createidx 150000 row { | ||
135 | CREATE INDEX i1a ON t1(a); | ||
136 | CREATE INDEX i1b ON t1(b); | ||
137 | CREATE INDEX i1c ON t1(c); | ||
138 | } | ||
139 | db eval COMMIT | ||
140 | |||
141 | # 5000 SELECTs on an integer comparison where the integer is | ||
142 | # indexed. | ||
143 | # | ||
144 | set sql {} | ||
145 | for {set i 0} {$i<5000} {incr i} { | ||
146 | set lwr [expr {$i*100}] | ||
147 | set upr [expr {($i+10)*100}] | ||
148 | append sql "SELECT count(*), avg(b) FROM t1 WHERE b>=$lwr AND b<$upr;" | ||
149 | } | ||
150 | db eval BEGIN | ||
151 | speed_trial speed1-select3 5000 stmt $sql | ||
152 | db eval COMMIT | ||
153 | |||
154 | # 100000 random SELECTs against rowid. | ||
155 | # | ||
156 | set sql {} | ||
157 | for {set i 1} {$i<=100000} {incr i} { | ||
158 | set id [expr {int(rand()*50000)+1}] | ||
159 | append sql "SELECT c FROM t1 WHERE rowid=$id;" | ||
160 | } | ||
161 | db eval BEGIN | ||
162 | speed_trial speed1-select4 100000 row $sql | ||
163 | db eval COMMIT | ||
164 | |||
165 | # 100000 random SELECTs against a unique indexed column. | ||
166 | # | ||
167 | set sql {} | ||
168 | for {set i 1} {$i<=100000} {incr i} { | ||
169 | set id [expr {int(rand()*50000)+1}] | ||
170 | append sql "SELECT c FROM t1 WHERE a=$id;" | ||
171 | } | ||
172 | db eval BEGIN | ||
173 | speed_trial speed1-select5 100000 row $sql | ||
174 | db eval COMMIT | ||
175 | |||
176 | # 50000 random SELECTs against an indexed column text column | ||
177 | # | ||
178 | set sql {} | ||
179 | db eval {SELECT c FROM t1 ORDER BY random() LIMIT 50000} { | ||
180 | append sql "SELECT c FROM t1 WHERE c='$c';" | ||
181 | } | ||
182 | db eval BEGIN | ||
183 | speed_trial speed1-select6 50000 row $sql | ||
184 | db eval COMMIT | ||
185 | |||
186 | |||
187 | # Vacuum | ||
188 | speed_trial speed1-vacuum 100000 row VACUUM | ||
189 | |||
190 | # 5000 updates of ranges where the field being compared is indexed. | ||
191 | # | ||
192 | set sql {} | ||
193 | for {set i 0} {$i<5000} {incr i} { | ||
194 | set lwr [expr {$i*2}] | ||
195 | set upr [expr {($i+1)*2}] | ||
196 | append sql "UPDATE t1 SET b=b*2 WHERE a>=$lwr AND a<$upr;" | ||
197 | } | ||
198 | db eval BEGIN | ||
199 | speed_trial speed1-update1 5000 stmt $sql | ||
200 | db eval COMMIT | ||
201 | |||
202 | # 50000 single-row updates. An index is used to find the row quickly. | ||
203 | # | ||
204 | set sql {} | ||
205 | for {set i 0} {$i<50000} {incr i} { | ||
206 | set r [expr {int(rand()*500000)}] | ||
207 | append sql "UPDATE t1 SET b=$r WHERE a=$i;" | ||
208 | } | ||
209 | db eval BEGIN | ||
210 | speed_trial speed1-update2 50000 row $sql | ||
211 | db eval COMMIT | ||
212 | |||
213 | # 1 big text update that touches every row in the table. | ||
214 | # | ||
215 | speed_trial speed1-update3 50000 row { | ||
216 | UPDATE t1 SET c=a; | ||
217 | } | ||
218 | |||
219 | # Many individual text updates. Each row in the table is | ||
220 | # touched through an index. | ||
221 | # | ||
222 | set sql {} | ||
223 | for {set i 1} {$i<=50000} {incr i} { | ||
224 | set r [expr {int(rand()*500000)}] | ||
225 | append sql "UPDATE t1 SET c='[number_name $r]' WHERE a=$i;" | ||
226 | } | ||
227 | db eval BEGIN | ||
228 | speed_trial speed1-update4 50000 row $sql | ||
229 | db eval COMMIT | ||
230 | |||
231 | # Delete all content in a table. | ||
232 | # | ||
233 | speed_trial speed1-delete1 50000 row {DELETE FROM t1} | ||
234 | |||
235 | # Copy one table into another | ||
236 | # | ||
237 | speed_trial speed1-copy1 50000 row {INSERT INTO t1 SELECT * FROM t2} | ||
238 | |||
239 | # Delete all content in a table, one row at a time. | ||
240 | # | ||
241 | speed_trial speed1-delete2 50000 row {DELETE FROM t1 WHERE 1} | ||
242 | |||
243 | # Refill the table yet again | ||
244 | # | ||
245 | speed_trial speed1-copy2 50000 row {INSERT INTO t1 SELECT * FROM t2} | ||
246 | |||
247 | # Drop the table and recreate it without its indices. | ||
248 | # | ||
249 | db eval BEGIN | ||
250 | speed_trial speed1-drop1 50000 row { | ||
251 | DROP TABLE t1; | ||
252 | CREATE TABLE t1(a INTEGER, b INTEGER, c TEXT); | ||
253 | } | ||
254 | db eval COMMIT | ||
255 | |||
256 | # Refill the table yet again. This copy should be faster because | ||
257 | # there are no indices to deal with. | ||
258 | # | ||
259 | speed_trial speed1-copy3 50000 row {INSERT INTO t1 SELECT * FROM t2} | ||
260 | |||
261 | # Select 20000 rows from the table at random. | ||
262 | # | ||
263 | speed_trial speed1-random1 50000 row { | ||
264 | SELECT rowid FROM t1 ORDER BY random() LIMIT 20000 | ||
265 | } | ||
266 | |||
267 | # Delete 20000 random rows from the table. | ||
268 | # | ||
269 | speed_trial speed1-random-del1 20000 row { | ||
270 | DELETE FROM t1 WHERE rowid IN | ||
271 | (SELECT rowid FROM t1 ORDER BY random() LIMIT 20000) | ||
272 | } | ||
273 | do_test speed1-1.1 { | ||
274 | db one {SELECT count(*) FROM t1} | ||
275 | } 30000 | ||
276 | |||
277 | |||
278 | # Delete 20000 more rows at random from the table. | ||
279 | # | ||
280 | speed_trial speed1-random-del2 20000 row { | ||
281 | DELETE FROM t1 WHERE rowid IN | ||
282 | (SELECT rowid FROM t1 ORDER BY random() LIMIT 20000) | ||
283 | } | ||
284 | do_test speed1-1.2 { | ||
285 | db one {SELECT count(*) FROM t1} | ||
286 | } 10000 | ||
287 | speed_trial_summary speed1 | ||
288 | |||
289 | finish_test | ||