From 45c236d81e1a95516b8d2ec1c7cfa6d0177aa1fd Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 22 Mar 2008 01:08:00 +0000 Subject: [PATCH] Add the speed1p.test script. Like speed1.test except that it tries to take advantage of prepared statements. (CVS 4907) FossilOrigin-Name: ece4fb9f7b93dc3e3cb77e40b011d013d0750dcf --- manifest | 15 +- manifest.uuid | 2 +- test/quick.test | 5 +- test/speed1p.test | 344 ++++++++++++++++++++++++++++++++++++++++++++++ test/tester.tcl | 17 ++- 5 files changed, 371 insertions(+), 12 deletions(-) create mode 100644 test/speed1p.test diff --git a/manifest b/manifest index 89ebeaa42c..54f59d29de 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sSQLITE_OMIT_DECLTYPE\scompile-time\soption.\s\sRemove\smore\scode\swhen\nSQLITE_ENABLE_COLUMN_METADATA\sis\snot\sdefined.\s(CVS\s4906) -D 2008-03-22T01:07:18 +C Add\sthe\sspeed1p.test\sscript.\s\sLike\sspeed1.test\sexcept\sthat\sit\stries\sto\stake\nadvantage\sof\sprepared\sstatements.\s(CVS\s4907) +D 2008-03-22T01:08:01 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7 F Makefile.in cf434ce8ca902e69126ae0f94fc9f7dc7428a5fa F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -419,7 +419,7 @@ F test/pragma2.test 5364893491b9231dd170e3459bfc2e2342658b47 F test/printf.test c3405535b418d454e8a52196a0fc592ec9eec58d F test/progress.test 5b075c3c790c7b2a61419bc199db87aaf48b8301 x F test/ptrchng.test 83150cb7b513e33cce90fdc68f4b1817551857c0 -F test/quick.test ee53085c09446208c70694bcc25dc717e1aa393f +F test/quick.test 037a953ccc4e5419c89528e7b93742db29bc3ec1 F test/quote.test 215897dbe8de1a6f701265836d6601cc6ed103e6 F test/rdonly.test b34db316525440d3b42c32e83942c02c37d28ef0 F test/reindex.test 38b138abe36bf9a08c791ed44d9f76cd6b97b78b @@ -447,6 +447,7 @@ F test/soak.test 64f9b27fbcdec43335a88c546ce1983e6ba40d7b F test/softheap1.test c9146eda576eedb62192b771293a2115d9af8456 F test/sort.test 0e4456e729e5a92a625907c63dcdedfbe72c5dc5 F test/speed1.test 22e1b27af0683ed44dcd2f93ed817a9c3e65084a +F test/speed1p.test 2c0144604a7c5d32493c4075c46d9a5a0f90ceba F test/speed2.test 53177056baf6556dcbdcf032bbdfc41c1aa74ded F test/speed3.test e312d7e442a5047d730569fdae2ba99bc94e1a13 F test/speed4.test 20d8ea20bea3ca09c3ef3b5ec820a17e58e132cb @@ -459,7 +460,7 @@ F test/table.test 13b1c2e2fb4727b35ee1fb7641fc469214fd2455 F test/tableapi.test 791f7e3891d9b70bdb43b311694bf5e9befcbc34 F test/tclsqlite.test 3fac87cb1059c46b8fa8a60b553f4f1adb0fb6d9 F test/temptable.test 19b851b9e3e64d91e9867619b2a3f5fffee6e125 -F test/tester.tcl 7e6e28cf813e132b84336cdd33804c1be2a1bc80 +F test/tester.tcl e7cc5f340ebd9107773e8684f5d7e10af6e63e0b F test/thread001.test 8fbd9559da0bbdc273e00318c7fd66c162020af7 F test/thread002.test 2c4ad2c386f60f6fe268cd91c769ee35b3c1fd0b F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35 @@ -624,7 +625,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 -P d8686abcdf9e566571033f2f137142f742df9357 -R aa65ee25792b35b0b257992140c3f662 +P 8ef26646cff9be75c584a9abfcfffcfdb49b3969 +R b10313284d733514a20b3e021e1c404e U drh -Z 466acf301fdb80b8f45999c2ef27b0df +Z 8edc416c1b9e2d24a4a52d0eea438ec4 diff --git a/manifest.uuid b/manifest.uuid index 2cba4055cd..8e6b70b43d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8ef26646cff9be75c584a9abfcfffcfdb49b3969 \ No newline at end of file +ece4fb9f7b93dc3e3cb77e40b011d013d0750dcf \ No newline at end of file diff --git a/test/quick.test b/test/quick.test index 242c76105f..7e8d58d66d 100644 --- a/test/quick.test +++ b/test/quick.test @@ -6,7 +6,7 @@ #*********************************************************************** # This file runs all tests. # -# $Id: quick.test,v 1.71 2008/03/20 16:26:49 danielk1977 Exp $ +# $Id: quick.test,v 1.72 2008/03/22 01:08:01 drh Exp $ proc lshift {lvar} { upvar $lvar l @@ -69,6 +69,7 @@ set EXCLUDE { quick.test soak.test speed1.test + speed1p.test speed2.test speed4.test sqllimits1.test @@ -113,5 +114,3 @@ source $testdir/misuse.test set sqlite_open_file_count 0 really_finish_test - - diff --git a/test/speed1p.test b/test/speed1p.test new file mode 100644 index 0000000000..387181df61 --- /dev/null +++ b/test/speed1p.test @@ -0,0 +1,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 diff --git a/test/tester.tcl b/test/tester.tcl index 73aca7cccc..f15f0cb28e 100644 --- a/test/tester.tcl +++ b/test/tester.tcl @@ -11,7 +11,7 @@ # 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 $ +# $Id: tester.tcl,v 1.110 2008/03/22 01:08:01 drh Exp $ set tcl_precision 15 @@ -171,6 +171,21 @@ proc speed_trial {name numstmt units sql} { 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] + global total_time + set total_time [expr {$total_time+$tm}] +} proc speed_trial_init {name} { global total_time set total_time 0