/ Check-in [ece4fb9f]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the speed1p.test script. Like speed1.test except that it tries to take advantage of prepared statements. (CVS 4907)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ece4fb9f7b93dc3e3cb77e40b011d013d0750dcf
User & Date: drh 2008-03-22 01:08:01
Context
2008-03-22
23:59
Bug fix in the newly revised sqllimit1.test script. (CVS 4908) check-in: 2a89fb3c user: drh tags: trunk
01:08
Add the speed1p.test script. Like speed1.test except that it tries to take advantage of prepared statements. (CVS 4907) check-in: ece4fb9f user: drh tags: trunk
01:07
Add the SQLITE_OMIT_DECLTYPE compile-time option. Remove more code when SQLITE_ENABLE_COLUMN_METADATA is not defined. (CVS 4906) check-in: 8ef26646 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to test/quick.test.

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
65
66
67
68
69
70
71

72
73
74
75
76
77
78
...
109
110
111
112
113
114
115
116
117
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file runs all tests.
#
# $Id: quick.test,v 1.71 2008/03/20 16:26:49 danielk1977 Exp $

proc lshift {lvar} {
  upvar $lvar l
  set ret [lindex $l 0]
  set l [lrange $l 1 end]
  return $ret
}
................................................................................
  memleak.test
  misc7.test
  misuse.test
  onefile.test
  quick.test
  soak.test
  speed1.test

  speed2.test
  speed4.test
  sqllimits1.test

  thread001.test
  thread002.test

................................................................................
    set sqlite_open_file_count 0
  }
}
source $testdir/misuse.test

set sqlite_open_file_count 0
really_finish_test









|







 







>







 







<
<
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
...
110
111
112
113
114
115
116


#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file runs all tests.
#
# $Id: quick.test,v 1.72 2008/03/22 01:08:01 drh Exp $

proc lshift {lvar} {
  upvar $lvar l
  set ret [lindex $l 0]
  set l [lrange $l 1 end]
  return $ret
}
................................................................................
  memleak.test
  misc7.test
  misuse.test
  onefile.test
  quick.test
  soak.test
  speed1.test
  speed1p.test
  speed2.test
  speed4.test
  sqllimits1.test

  thread001.test
  thread002.test

................................................................................
    set sqlite_open_file_count 0
  }
}
source $testdir/misuse.test

set sqlite_open_file_count 0
really_finish_test


Added test/speed1p.test.

















































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
# 2008 March 21
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#*************************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script is measuring executing speed.  
#
# This is a copy of speed1.test modified to user prepared statements.
#
# $Id: speed1p.test,v 1.1 2008/03/22 01:08:01 drh Exp $
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl
speed_trial_init speed1

# Set a uniform random seed
expr srand(0)

set sqlout [open speed1.txt w]
proc tracesql {sql} {
  puts $::sqlout $sql\;
}
#db trace tracesql

# The number_name procedure below converts its argment (an integer)
# into a string which is the English-language name for that number.
#
# Example:
#
#     puts [number_name 123]   ->  "one hundred twenty three"
#
set ones {zero one two three four five six seven eight nine
          ten eleven twelve thirteen fourteen fifteen sixteen seventeen
          eighteen nineteen}
set tens {{} ten twenty thirty forty fifty sixty seventy eighty ninety}
proc number_name {n} {
  if {$n>=1000} {
    set txt "[number_name [expr {$n/1000}]] thousand"
    set n [expr {$n%1000}]
  } else {
    set txt {}
  }
  if {$n>=100} {
    append txt " [lindex $::ones [expr {$n/100}]] hundred"
    set n [expr {$n%100}]
  }
  if {$n>=20} {
    append txt " [lindex $::tens [expr {$n/10}]]"
    set n [expr {$n%10}]
  }
  if {$n>0} {
    append txt " [lindex $::ones $n]"
  }
  set txt [string trim $txt]
  if {$txt==""} {set txt zero}
  return $txt
}

# Create a database schema.
#
do_test speed1p-1.0 {
  execsql {
    PRAGMA page_size=1024;
    PRAGMA cache_size=8192;
    PRAGMA locking_mode=EXCLUSIVE;
    CREATE TABLE t1(a INTEGER, b INTEGER, c TEXT);
    CREATE TABLE t2(a INTEGER, b INTEGER, c TEXT);
    CREATE INDEX i2a ON t2(a);
    CREATE INDEX i2b ON t2(b);
  }
  execsql {
    SELECT name FROM sqlite_master ORDER BY 1;
  }
} {i2a i2b t1 t2}


# 50000 INSERTs on an unindexed table
#
set list {}
for {set i 1} {$i<=50000} {incr i} {
  set r [expr {int(rand()*500000)}]
  set x [number_name $r]
  lappend list $i $r $x
}
set script {
  foreach {i r x} $::list {
    db eval {INSERT INTO t1 VALUES($i,$r,$x)}
  }
}
db eval BEGIN
speed_trial_tcl speed1p-insert1 50000 row $script
db eval COMMIT

# 50000 INSERTs on an indexed table
#
set list {}
for {set i 1} {$i<=50000} {incr i} {
  set r [expr {int(rand()*500000)}]
  set x [number_name $r]
  lappend list $i $r $x
}
set script {
  foreach {i r x} $::list {
    db eval {INSERT INTO t2 VALUES($i,$r,$x)}
  }
}
db eval BEGIN
speed_trial_tcl speed1p-insert2 50000 row $script
db eval COMMIT



# 50 SELECTs on an integer comparison.  There is no index so
# a full table scan is required.
#
set list {}
for {set i 0} {$i<50} {incr i} {
  set lwr [expr {$i*100}]
  set upr [expr {($i+10)*100}]
  lappend list $lwr $upr
}
set script {
  foreach {lwr upr} $::list {
    db eval  {SELECT count(*), avg(b) FROM t1 WHERE b>=$lwr AND b<$upr}
  }
}
db eval BEGIN
speed_trial_tcl speed1p-select1 [expr {50*50000}] row $script
db eval COMMIT

# 50 SELECTs on an LIKE comparison.  There is no index so a full
# table scan is required.
#
set list {}
for {set i 0} {$i<50} {incr i} {
  lappend list "%[number_name $i]%"
}
set script {
  foreach pattern $::list {
    db eval {SELECT count(*), avg(b) FROM t1 WHERE c LIKE $pattern}
  }
}
db eval BEGIN
speed_trial_tcl speed1p-select2 [expr {50*50000}] row $script
db eval COMMIT

# Create indices
#
db eval BEGIN
speed_trial speed1p-createidx 150000 row {
  CREATE INDEX i1a ON t1(a);
  CREATE INDEX i1b ON t1(b);
  CREATE INDEX i1c ON t1(c);
}
db eval COMMIT

# 5000 SELECTs on an integer comparison where the integer is
# indexed.
#
set list {}
for {set i 0} {$i<5000} {incr i} {
  set lwr [expr {$i*100}]
  set upr [expr {($i+10)*100}]
  lappend list $lwr $upr
}
set script {
  foreach {lwr upr} $::list {
    db eval {SELECT count(*), avg(b) FROM t1 WHERE b>=$lwr AND b<$upr}
  }
}
db eval BEGIN
speed_trial_tcl speed1p-select3 5000 stmt $script
db eval COMMIT

# 100000 random SELECTs against rowid.
#
set list {}
for {set i 1} {$i<=100000} {incr i} {
  set id [expr {int(rand()*50000)+1}]
  lappend list $id
}
set script {
  foreach id $::list {
    db eval {SELECT c FROM t1 WHERE rowid=$id}
  }
}
db eval BEGIN
speed_trial_tcl speed1p-select4 100000 row $script
db eval COMMIT

# 100000 random SELECTs against a unique indexed column.
#
set list {}
for {set i 1} {$i<=100000} {incr i} {
  set id [expr {int(rand()*50000)+1}]
  lappend list $id
}
set script {
  foreach id $::list {
    db eval {SELECT c FROM t1 WHERE a=$id}
  }
}
db eval BEGIN
speed_trial_tcl speed1p-select5 100000 row $script
db eval COMMIT

# 50000 random SELECTs against an indexed column text column
#
set list [db eval {SELECT c FROM t1 ORDER BY random() LIMIT 50000}]
set script {
  foreach c $::list {
    db eval {SELECT c FROM t1 WHERE c=$c}
  }
}
db eval BEGIN
speed_trial_tcl speed1p-select6 50000 row $script
db eval COMMIT


# Vacuum
speed_trial speed1p-vacuum 100000 row VACUUM

# 5000 updates of ranges where the field being compared is indexed.
#
set list {}
for {set i 0} {$i<5000} {incr i} {
  set lwr [expr {$i*2}]
  set upr [expr {($i+1)*2}]
  lappend list $lwr $upr
}
set script {
  foreach {lwr upr} $::list {
    db eval {UPDATE t1 SET b=b*2 WHERE a>=$lwr AND a<$upr}
  }
}
db eval BEGIN
speed_trial_tcl speed1p-update1 5000 stmt $script
db eval COMMIT

# 50000 single-row updates.  An index is used to find the row quickly.
#
set list {}
for {set i 0} {$i<50000} {incr i} {
  set r [expr {int(rand()*500000)}]
  lappend list $i $r
}
set script {
  foreach {i r} $::list {
    db eval {UPDATE t1 SET b=$r WHERE a=$i}
  }
}
db eval BEGIN
speed_trial_tcl speed1p-update2 50000 row $script
db eval COMMIT

# 1 big text update that touches every row in the table.
#
speed_trial speed1p-update3 50000 row {
  UPDATE t1 SET c=a;
}

# Many individual text updates.  Each row in the table is
# touched through an index.
#
set list {}
for {set i 1} {$i<=50000} {incr i} {
  set r [expr {int(rand()*500000)}]
  lappend list $i [number_name $r]
}
set script {
  foreach {i x} $::list {
    db eval {UPDATE t1 SET c=$x WHERE a=$i}
  }
}
db eval BEGIN
speed_trial_tcl speed1p-update4 50000 row $script
db eval COMMIT

# Delete all content in a table.
#
speed_trial speed1p-delete1 50000 row {DELETE FROM t1}

# Copy one table into another
#
speed_trial speed1p-copy1 50000 row {INSERT INTO t1 SELECT * FROM t2}

# Delete all content in a table, one row at a time.
#
speed_trial speed1p-delete2 50000 row {DELETE FROM t1 WHERE 1}

# Refill the table yet again
#
speed_trial speed1p-copy2 50000 row {INSERT INTO t1 SELECT * FROM t2}

# Drop the table and recreate it without its indices.
#
db eval BEGIN
speed_trial speed1p-drop1 50000 row {
   DROP TABLE t1;
   CREATE TABLE t1(a INTEGER, b INTEGER, c TEXT);
}
db eval COMMIT

# Refill the table yet again.  This copy should be faster because
# there are no indices to deal with.
#
speed_trial speed1p-copy3 50000 row {INSERT INTO t1 SELECT * FROM t2}

# Select 20000 rows from the table at random.
#
speed_trial speed1p-random1 50000 row {
  SELECT rowid FROM t1 ORDER BY random() LIMIT 20000
}

# Delete 20000 random rows from the table.
#
speed_trial speed1p-random-del1 20000 row {
  DELETE FROM t1 WHERE rowid IN
    (SELECT rowid FROM t1 ORDER BY random() LIMIT 20000)
}
do_test speed1p-1.1 {
  db one {SELECT count(*) FROM t1}
} 30000

    
# Delete 20000 more rows at random from the table.
#
speed_trial speed1p-random-del2 20000 row {
  DELETE FROM t1 WHERE rowid IN
    (SELECT rowid FROM t1 ORDER BY random() LIMIT 20000)
}
do_test speed1p-1.2 {
  db one {SELECT count(*) FROM t1}
} 10000
speed_trial_summary speed1

finish_test

Changes to test/tester.tcl.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
157
158
159
160
161
162
163















164
165
166
167
168
169
170
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements some common TCL routines used for regression
# testing the SQLite library
#
# $Id: tester.tcl,v 1.109 2008/03/21 17:29:38 danielk1977 Exp $


set tcl_precision 15
set sqlite_pending_byte 0x0010000

# 
# Check the command-line arguments for a default soft-heap-limit.
................................................................................
# Return the number of microseconds per statement.
#
proc speed_trial {name numstmt units sql} {
  puts -nonewline [format {%-21.21s } $name...]
  flush stdout
  set speed [time {sqlite3_exec_nr db $sql}]
  set tm [lindex $speed 0]















  if {$tm == 0} {
    set rate [format %20s "many"]
  } else {
    set rate [format %20.5f [expr {1000000.0*$numstmt/$tm}]]
  }
  set u2 $units/s
  puts [format {%12d uS %s %s} $tm $rate $u2]







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements some common TCL routines used for regression
# testing the SQLite library
#
# $Id: tester.tcl,v 1.110 2008/03/22 01:08:01 drh Exp $


set tcl_precision 15
set sqlite_pending_byte 0x0010000

# 
# Check the command-line arguments for a default soft-heap-limit.
................................................................................
# Return the number of microseconds per statement.
#
proc speed_trial {name numstmt units sql} {
  puts -nonewline [format {%-21.21s } $name...]
  flush stdout
  set speed [time {sqlite3_exec_nr db $sql}]
  set tm [lindex $speed 0]
  if {$tm == 0} {
    set rate [format %20s "many"]
  } else {
    set rate [format %20.5f [expr {1000000.0*$numstmt/$tm}]]
  }
  set u2 $units/s
  puts [format {%12d uS %s %s} $tm $rate $u2]
  global total_time
  set total_time [expr {$total_time+$tm}]
}
proc speed_trial_tcl {name numstmt units script} {
  puts -nonewline [format {%-21.21s } $name...]
  flush stdout
  set speed [time {eval $script}]
  set tm [lindex $speed 0]
  if {$tm == 0} {
    set rate [format %20s "many"]
  } else {
    set rate [format %20.5f [expr {1000000.0*$numstmt/$tm}]]
  }
  set u2 $units/s
  puts [format {%12d uS %s %s} $tm $rate $u2]