os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/speed1p.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/speed1p.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,342 @@
     1.4 +# 2008 March 21
     1.5 +#
     1.6 +# The author disclaims copyright to this source code.  In place of
     1.7 +# a legal notice, here is a blessing:
     1.8 +#
     1.9 +#    May you do good and not evil.
    1.10 +#    May you find forgiveness for yourself and forgive others.
    1.11 +#    May you share freely, never taking more than you give.
    1.12 +#
    1.13 +#*************************************************************************
    1.14 +# This file implements regression tests for SQLite library.  The
    1.15 +# focus of this script is measuring executing speed.  
    1.16 +#
    1.17 +# This is a copy of speed1.test modified to user prepared statements.
    1.18 +#
    1.19 +# $Id: speed1p.test,v 1.5 2008/07/30 13:15:46 drh Exp $
    1.20 +#
    1.21 +
    1.22 +sqlite3_shutdown
    1.23 +#sqlite3_config_scratch 29000 1
    1.24 +sqlite3_config_lookaside 2048 300
    1.25 +#sqlite3_config_pagecache 1024 11000
    1.26 +set testdir [file dirname $argv0]
    1.27 +source $testdir/tester.tcl
    1.28 +speed_trial_init speed1
    1.29 +
    1.30 +# Set a uniform random seed
    1.31 +expr srand(0)
    1.32 +
    1.33 +# The number_name procedure below converts its argment (an integer)
    1.34 +# into a string which is the English-language name for that number.
    1.35 +#
    1.36 +# Example:
    1.37 +#
    1.38 +#     puts [number_name 123]   ->  "one hundred twenty three"
    1.39 +#
    1.40 +set ones {zero one two three four five six seven eight nine
    1.41 +          ten eleven twelve thirteen fourteen fifteen sixteen seventeen
    1.42 +          eighteen nineteen}
    1.43 +set tens {{} ten twenty thirty forty fifty sixty seventy eighty ninety}
    1.44 +proc number_name {n} {
    1.45 +  if {$n>=1000} {
    1.46 +    set txt "[number_name [expr {$n/1000}]] thousand"
    1.47 +    set n [expr {$n%1000}]
    1.48 +  } else {
    1.49 +    set txt {}
    1.50 +  }
    1.51 +  if {$n>=100} {
    1.52 +    append txt " [lindex $::ones [expr {$n/100}]] hundred"
    1.53 +    set n [expr {$n%100}]
    1.54 +  }
    1.55 +  if {$n>=20} {
    1.56 +    append txt " [lindex $::tens [expr {$n/10}]]"
    1.57 +    set n [expr {$n%10}]
    1.58 +  }
    1.59 +  if {$n>0} {
    1.60 +    append txt " [lindex $::ones $n]"
    1.61 +  }
    1.62 +  set txt [string trim $txt]
    1.63 +  if {$txt==""} {set txt zero}
    1.64 +  return $txt
    1.65 +}
    1.66 +
    1.67 +# Create a database schema.
    1.68 +#
    1.69 +do_test speed1p-1.0 {
    1.70 +  execsql {
    1.71 +    PRAGMA page_size=1024;
    1.72 +    PRAGMA cache_size=500;
    1.73 +    PRAGMA locking_mode=EXCLUSIVE;
    1.74 +    CREATE TABLE t1(a INTEGER, b INTEGER, c TEXT);
    1.75 +    CREATE TABLE t2(a INTEGER, b INTEGER, c TEXT);
    1.76 +    CREATE INDEX i2a ON t2(a);
    1.77 +    CREATE INDEX i2b ON t2(b);
    1.78 +  }
    1.79 +  execsql {
    1.80 +    SELECT name FROM sqlite_master ORDER BY 1;
    1.81 +  }
    1.82 +} {i2a i2b t1 t2}
    1.83 +
    1.84 +
    1.85 +# 50000 INSERTs on an unindexed table
    1.86 +#
    1.87 +set list {}
    1.88 +for {set i 1} {$i<=50000} {incr i} {
    1.89 +  set r [expr {int(rand()*500000)}]
    1.90 +  set x [number_name $r]
    1.91 +  lappend list $i $r $x
    1.92 +}
    1.93 +set script {
    1.94 +  foreach {i r x} $::list {
    1.95 +    db eval {INSERT INTO t1 VALUES($i,$r,$x)}
    1.96 +  }
    1.97 +}
    1.98 +db eval BEGIN
    1.99 +speed_trial_tcl speed1p-insert1 50000 row $script
   1.100 +db eval COMMIT
   1.101 +
   1.102 +# 50000 INSERTs on an indexed table
   1.103 +#
   1.104 +set list {}
   1.105 +for {set i 1} {$i<=50000} {incr i} {
   1.106 +  set r [expr {int(rand()*500000)}]
   1.107 +  set x [number_name $r]
   1.108 +  lappend list $i $r $x
   1.109 +}
   1.110 +set script {
   1.111 +  foreach {i r x} $::list {
   1.112 +    db eval {INSERT INTO t2 VALUES($i,$r,$x)}
   1.113 +  }
   1.114 +}
   1.115 +db eval BEGIN
   1.116 +speed_trial_tcl speed1p-insert2 50000 row $script
   1.117 +db eval COMMIT
   1.118 +
   1.119 +
   1.120 +
   1.121 +# 50 SELECTs on an integer comparison.  There is no index so
   1.122 +# a full table scan is required.
   1.123 +#
   1.124 +set list {}
   1.125 +for {set i 0} {$i<50} {incr i} {
   1.126 +  set lwr [expr {$i*100}]
   1.127 +  set upr [expr {($i+10)*100}]
   1.128 +  lappend list $lwr $upr
   1.129 +}
   1.130 +set script {
   1.131 +  foreach {lwr upr} $::list {
   1.132 +    db eval  {SELECT count(*), avg(b) FROM t1 WHERE b>=$lwr AND b<$upr}
   1.133 +  }
   1.134 +}
   1.135 +db eval BEGIN
   1.136 +speed_trial_tcl speed1p-select1 [expr {50*50000}] row $script
   1.137 +db eval COMMIT
   1.138 +
   1.139 +# 50 SELECTs on an LIKE comparison.  There is no index so a full
   1.140 +# table scan is required.
   1.141 +#
   1.142 +set list {}
   1.143 +for {set i 0} {$i<50} {incr i} {
   1.144 +  lappend list "%[number_name $i]%"
   1.145 +}
   1.146 +set script {
   1.147 +  foreach pattern $::list {
   1.148 +    db eval {SELECT count(*), avg(b) FROM t1 WHERE c LIKE $pattern}
   1.149 +  }
   1.150 +}
   1.151 +db eval BEGIN
   1.152 +speed_trial_tcl speed1p-select2 [expr {50*50000}] row $script
   1.153 +db eval COMMIT
   1.154 +
   1.155 +# Create indices
   1.156 +#
   1.157 +db eval BEGIN
   1.158 +speed_trial speed1p-createidx 150000 row {
   1.159 +  CREATE INDEX i1a ON t1(a);
   1.160 +  CREATE INDEX i1b ON t1(b);
   1.161 +  CREATE INDEX i1c ON t1(c);
   1.162 +}
   1.163 +db eval COMMIT
   1.164 +
   1.165 +# 5000 SELECTs on an integer comparison where the integer is
   1.166 +# indexed.
   1.167 +#
   1.168 +set list {}
   1.169 +for {set i 0} {$i<5000} {incr i} {
   1.170 +  set lwr [expr {$i*100}]
   1.171 +  set upr [expr {($i+10)*100}]
   1.172 +  lappend list $lwr $upr
   1.173 +}
   1.174 +set script {
   1.175 +  foreach {lwr upr} $::list {
   1.176 +    db eval {SELECT count(*), avg(b) FROM t1 WHERE b>=$lwr AND b<$upr}
   1.177 +  }
   1.178 +}
   1.179 +db eval BEGIN
   1.180 +speed_trial_tcl speed1p-select3 5000 stmt $script
   1.181 +db eval COMMIT
   1.182 +
   1.183 +# 100000 random SELECTs against rowid.
   1.184 +#
   1.185 +set list {}
   1.186 +for {set i 1} {$i<=100000} {incr i} {
   1.187 +  set id [expr {int(rand()*50000)+1}]
   1.188 +  lappend list $id
   1.189 +}
   1.190 +set script {
   1.191 +  foreach id $::list {
   1.192 +    db eval {SELECT c FROM t1 WHERE rowid=$id}
   1.193 +  }
   1.194 +}
   1.195 +db eval BEGIN
   1.196 +speed_trial_tcl speed1p-select4 100000 row $script
   1.197 +db eval COMMIT
   1.198 +
   1.199 +# 100000 random SELECTs against a unique indexed column.
   1.200 +#
   1.201 +set list {}
   1.202 +for {set i 1} {$i<=100000} {incr i} {
   1.203 +  set id [expr {int(rand()*50000)+1}]
   1.204 +  lappend list $id
   1.205 +}
   1.206 +set script {
   1.207 +  foreach id $::list {
   1.208 +    db eval {SELECT c FROM t1 WHERE a=$id}
   1.209 +  }
   1.210 +}
   1.211 +db eval BEGIN
   1.212 +speed_trial_tcl speed1p-select5 100000 row $script
   1.213 +db eval COMMIT
   1.214 +
   1.215 +# 50000 random SELECTs against an indexed column text column
   1.216 +#
   1.217 +set list [db eval {SELECT c FROM t1 ORDER BY random() LIMIT 50000}]
   1.218 +set script {
   1.219 +  foreach c $::list {
   1.220 +    db eval {SELECT c FROM t1 WHERE c=$c}
   1.221 +  }
   1.222 +}
   1.223 +db eval BEGIN
   1.224 +speed_trial_tcl speed1p-select6 50000 row $script
   1.225 +db eval COMMIT
   1.226 +
   1.227 +
   1.228 +# Vacuum
   1.229 +speed_trial speed1p-vacuum 100000 row VACUUM
   1.230 +
   1.231 +# 5000 updates of ranges where the field being compared is indexed.
   1.232 +#
   1.233 +set list {}
   1.234 +for {set i 0} {$i<5000} {incr i} {
   1.235 +  set lwr [expr {$i*2}]
   1.236 +  set upr [expr {($i+1)*2}]
   1.237 +  lappend list $lwr $upr
   1.238 +}
   1.239 +set script {
   1.240 +  foreach {lwr upr} $::list {
   1.241 +    db eval {UPDATE t1 SET b=b*2 WHERE a>=$lwr AND a<$upr}
   1.242 +  }
   1.243 +}
   1.244 +db eval BEGIN
   1.245 +speed_trial_tcl speed1p-update1 5000 stmt $script
   1.246 +db eval COMMIT
   1.247 +
   1.248 +# 50000 single-row updates.  An index is used to find the row quickly.
   1.249 +#
   1.250 +set list {}
   1.251 +for {set i 0} {$i<50000} {incr i} {
   1.252 +  set r [expr {int(rand()*500000)}]
   1.253 +  lappend list $i $r
   1.254 +}
   1.255 +set script {
   1.256 +  foreach {i r} $::list {
   1.257 +    db eval {UPDATE t1 SET b=$r WHERE a=$i}
   1.258 +  }
   1.259 +}
   1.260 +db eval BEGIN
   1.261 +speed_trial_tcl speed1p-update2 50000 row $script
   1.262 +db eval COMMIT
   1.263 +
   1.264 +# 1 big text update that touches every row in the table.
   1.265 +#
   1.266 +speed_trial speed1p-update3 50000 row {
   1.267 +  UPDATE t1 SET c=a;
   1.268 +}
   1.269 +
   1.270 +# Many individual text updates.  Each row in the table is
   1.271 +# touched through an index.
   1.272 +#
   1.273 +set list {}
   1.274 +for {set i 1} {$i<=50000} {incr i} {
   1.275 +  set r [expr {int(rand()*500000)}]
   1.276 +  lappend list $i [number_name $r]
   1.277 +}
   1.278 +set script {
   1.279 +  foreach {i x} $::list {
   1.280 +    db eval {UPDATE t1 SET c=$x WHERE a=$i}
   1.281 +  }
   1.282 +}
   1.283 +db eval BEGIN
   1.284 +speed_trial_tcl speed1p-update4 50000 row $script
   1.285 +db eval COMMIT
   1.286 +
   1.287 +# Delete all content in a table.
   1.288 +#
   1.289 +speed_trial speed1p-delete1 50000 row {DELETE FROM t1}
   1.290 +
   1.291 +# Copy one table into another
   1.292 +#
   1.293 +speed_trial speed1p-copy1 50000 row {INSERT INTO t1 SELECT * FROM t2}
   1.294 +
   1.295 +# Delete all content in a table, one row at a time.
   1.296 +#
   1.297 +speed_trial speed1p-delete2 50000 row {DELETE FROM t1 WHERE 1}
   1.298 +
   1.299 +# Refill the table yet again
   1.300 +#
   1.301 +speed_trial speed1p-copy2 50000 row {INSERT INTO t1 SELECT * FROM t2}
   1.302 +
   1.303 +# Drop the table and recreate it without its indices.
   1.304 +#
   1.305 +db eval BEGIN
   1.306 +speed_trial speed1p-drop1 50000 row {
   1.307 +   DROP TABLE t1;
   1.308 +   CREATE TABLE t1(a INTEGER, b INTEGER, c TEXT);
   1.309 +}
   1.310 +db eval COMMIT
   1.311 +
   1.312 +# Refill the table yet again.  This copy should be faster because
   1.313 +# there are no indices to deal with.
   1.314 +#
   1.315 +speed_trial speed1p-copy3 50000 row {INSERT INTO t1 SELECT * FROM t2}
   1.316 +
   1.317 +# Select 20000 rows from the table at random.
   1.318 +#
   1.319 +speed_trial speed1p-random1 50000 row {
   1.320 +  SELECT rowid FROM t1 ORDER BY random() LIMIT 20000
   1.321 +}
   1.322 +
   1.323 +# Delete 20000 random rows from the table.
   1.324 +#
   1.325 +speed_trial speed1p-random-del1 20000 row {
   1.326 +  DELETE FROM t1 WHERE rowid IN
   1.327 +    (SELECT rowid FROM t1 ORDER BY random() LIMIT 20000)
   1.328 +}
   1.329 +do_test speed1p-1.1 {
   1.330 +  db one {SELECT count(*) FROM t1}
   1.331 +} 30000
   1.332 +
   1.333 +    
   1.334 +# Delete 20000 more rows at random from the table.
   1.335 +#
   1.336 +speed_trial speed1p-random-del2 20000 row {
   1.337 +  DELETE FROM t1 WHERE rowid IN
   1.338 +    (SELECT rowid FROM t1 ORDER BY random() LIMIT 20000)
   1.339 +}
   1.340 +do_test speed1p-1.2 {
   1.341 +  db one {SELECT count(*) FROM t1}
   1.342 +} 10000
   1.343 +speed_trial_summary speed1
   1.344 +
   1.345 +finish_test