]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Added the speed4p.test script for testing performance of views and triggers. (CVS...
authordrh <drh@noemail.net>
Thu, 27 Mar 2008 15:07:04 +0000 (15:07 +0000)
committerdrh <drh@noemail.net>
Thu, 27 Mar 2008 15:07:04 +0000 (15:07 +0000)
FossilOrigin-Name: adf7645f9a1e12389a7511d2adca9013b7f330fa

manifest
manifest.uuid
test/quick.test
test/speed4p.test [new file with mode: 0644]

index dfb6a841e9fcb97da2317f36ed7f14389524ef67..5dcfcfafac14b3d76a11a9b5cc99cc91a9853cc7 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Changes\sto\sdelay\sfreeing\sbuffers\sassociated\swith\svdbe\smemory\scells\suntil\seither\ssqlite3_finalize()\sor\ssqlite3_release_memory()\sis\scalled.\s(CVS\s4922)
-D 2008-03-26T18:34:43
+C Added\sthe\sspeed4p.test\sscript\sfor\stesting\sperformance\sof\sviews\sand\striggers.\s(CVS\s4923)
+D 2008-03-27T15:07:05
 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
 F Makefile.in cf434ce8ca902e69126ae0f94fc9f7dc7428a5fa
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -411,7 +411,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 fcd8fb7aeee4b8bc7a5be56c25104f6f39258eb1
+F test/quick.test 164584ef7c350b6c439d29f248fc582d5262e71c
 F test/quote.test 215897dbe8de1a6f701265836d6601cc6ed103e6
 F test/rdonly.test b34db316525440d3b42c32e83942c02c37d28ef0
 F test/reindex.test 38b138abe36bf9a08c791ed44d9f76cd6b97b78b
@@ -443,6 +443,7 @@ F test/speed1p.test 2c0144604a7c5d32493c4075c46d9a5a0f90ceba
 F test/speed2.test 53177056baf6556dcbdcf032bbdfc41c1aa74ded
 F test/speed3.test e312d7e442a5047d730569fdae2ba99bc94e1a13
 F test/speed4.test 20d8ea20bea3ca09c3ef3b5ec820a17e58e132cb
+F test/speed4p.test c2633dc73f4206deffd8e8c34fe5a2dc0ab97800
 F test/sqllimits1.test cebd870957dbf8d931c5c9cadf757e0d31a3f71a
 F test/subquery.test 8203f85db56ba022a57a0589890090c8feed4e59
 F test/subselect.test 974e87f8fc91c5f00dd565316d396a5a6c3106c4
@@ -618,7 +619,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
-P afe1963ec5588d2195f027fa438cf63d49c89cd9
-R 214d193014a5eff088fafe70f8060fb1
-U danielk1977
-Z ddfa33c54c6e0388e4067b98a41cbe5a
+P 8c2f69521f13bc24cf005520efbe0589eeadd763
+R 0fca44539a2917afad155100f6434a4c
+U drh
+Z 074101a796f99fca1a50c6aac650887e
index 464d2eff6887d19a26b6bf9121fd74f54ff13d7a..c5c3143650b20cf26bd1bedca2cb555450c0102b 100644 (file)
@@ -1 +1 @@
-8c2f69521f13bc24cf005520efbe0589eeadd763
\ No newline at end of file
+adf7645f9a1e12389a7511d2adca9013b7f330fa
\ No newline at end of file
index 68e86ddb9ac73f51e63c868205af66e511570eb2..3b56748bcaf12d8f9d1a45171d4350b96ea36436 100644 (file)
@@ -6,7 +6,7 @@
 #***********************************************************************
 # This file runs all tests.
 #
-# $Id: quick.test,v 1.73 2008/03/25 00:22:22 drh Exp $
+# $Id: quick.test,v 1.74 2008/03/27 15:07:05 drh Exp $
 
 proc lshift {lvar} {
   upvar $lvar l
@@ -67,6 +67,7 @@ set EXCLUDE {
   speed1p.test
   speed2.test
   speed4.test
+  soeed4p.test
   sqllimits1.test
 
   thread001.test
diff --git a/test/speed4p.test b/test/speed4p.test
new file mode 100644 (file)
index 0000000..d7050e8
--- /dev/null
@@ -0,0 +1,265 @@
+# 2007 October 23
+#
+# 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. More specifically,
+# the focus is on the speed of:
+#
+#   * joins
+#   * views
+#   * sub-selects
+#   * triggers
+#
+# $Id: speed4p.test,v 1.1 2008/03/27 15:07:05 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
+}
+
+# Summary of tests:
+#
+#   speed4p-join1: Join three tables using IPK index.
+#   speed4p-join2: Join three tables using an index.
+#   speed4p-join3: Join two tables without an index.
+#
+#   speed4p-view1:  Querying a view.
+#   speed4p-table1: Same queries as in speed4p-view1, but run directly against
+#                  the tables for comparison purposes.
+#
+#   speed4p-subselect1: A SELECT statement that uses many sub-queries..
+#
+#   speed4p-trigger1: An INSERT statement that fires a trigger.
+#   speed4p-trigger2: An UPDATE statement that fires a trigger.
+#   speed4p-trigger3: A DELETE statement that fires a trigger.
+#   speed4p-notrigger1: Same operation as trigger1, but without the trigger.
+#   speed4p-notrigger2:        "          trigger2           "
+#   speed4p-notrigger3:        "          trigger3           "
+#
+
+# Set up the schema. Each of the tables t1, t2 and t3 contain 50,000 rows.
+# This creates a database of around 16MB.
+execsql {
+  BEGIN;
+  CREATE TABLE t1(rowid INTEGER PRIMARY KEY, i INTEGER, t TEXT);
+  CREATE TABLE t2(rowid INTEGER PRIMARY KEY, i INTEGER, t TEXT);
+  CREATE TABLE t3(rowid INTEGER PRIMARY KEY, i INTEGER, t TEXT);
+
+  CREATE VIEW v1 AS SELECT rowid, i, t FROM t1;
+  CREATE VIEW v2 AS SELECT rowid, i, t FROM t2;
+  CREATE VIEW v3 AS SELECT rowid, i, t FROM t3;
+}
+for {set jj 1} {$jj <= 3} {incr jj} {
+  set stmt [string map "%T% t$jj" {INSERT INTO %T% VALUES(NULL, $i, $t)}]
+  for {set ii 0} {$ii < 50000} {incr ii} {
+    set i [expr {int(rand()*50000)}]
+    set t [number_name $i]
+    execsql $stmt
+  }
+}
+execsql {
+  CREATE INDEX i1 ON t1(t);
+  CREATE INDEX i2 ON t2(t);
+  CREATE INDEX i3 ON t3(t);
+  COMMIT;
+}
+
+# Before running these tests, disable the compiled statement cache built into
+# the Tcl interface. This is because we want to test the speed of SQL
+# compilation as well as execution.
+#
+db cache size 0
+
+# Join t1, t2, t3 on IPK.
+set sql "SELECT * FROM t1, t2, t3 WHERE t1.oid = t2.oid AND t2.oid = t3.oid"
+speed_trial speed4p-join1 50000 row $sql
+
+# Join t1, t2, t3 on the non-IPK index.
+set sql "SELECT * FROM t1, t2, t3 WHERE t1.t = t2.t AND t2.t = t3.t"
+speed_trial speed4p-join2 50000 row $sql
+
+# Run 10000 simple queries against the views.
+set script {
+  for {set ii 1} {$ii < 10000} {incr ii} {
+    set v [expr {$ii*3}]
+    set t [expr {$ii%3+1}]
+    db eval "SELECT * FROM v$t WHERE rowid = \$v"
+  }
+}
+speed_trial_tcl speed4p-view1 10000 stmt $script
+
+# Run the same 10000 simple queries as in the previous test case against
+# the underlying tables. The compiled vdbe programs should be identical, so
+# the only difference in running time is the extra time taken to compile
+# the view definitions.
+#
+set script {
+  for {set ii 1} {$ii < 10000} {incr ii} {
+    set v [expr {$ii*3}]
+    set t [expr {$ii%3+1}]
+    db eval "SELECT t FROM t$t WHERE rowid = \$v"
+  }
+}
+speed_trial_tcl speed4p-table1 10000 stmt $script
+
+# Run a SELECT that uses sub-queries 10000 times. A total of 30000 sub-selects.
+#
+set script {
+  for {set ii 1} {$ii < 10000} {incr ii} {
+    set v [expr {$ii*3}]
+    db eval {
+      SELECT (SELECT t FROM t1 WHERE rowid = $v), 
+             (SELECT t FROM t2 WHERE rowid = $v), 
+             (SELECT t FROM t3 WHERE rowid = $v)
+    }
+  }
+}
+speed_trial_tcl speed4p-subselect1 10000 stmt $script
+
+# The following block tests the speed of some DML statements that cause
+# triggers to fire.
+#
+execsql {
+  CREATE TABLE log(op TEXT, r INTEGER, i INTEGER, t TEXT);
+  CREATE TABLE t4(rowid INTEGER PRIMARY KEY, i INTEGER, t TEXT);
+  CREATE TRIGGER t4_trigger1 AFTER INSERT ON t4 BEGIN
+    INSERT INTO log VALUES('INSERT INTO t4', new.rowid, new.i, new.t);
+  END;
+  CREATE TRIGGER t4_trigger2 AFTER UPDATE ON t4 BEGIN
+    INSERT INTO log VALUES('UPDATE OF t4', new.rowid, new.i, new.t);
+  END;
+  CREATE TRIGGER t4_trigger3 AFTER DELETE ON t4 BEGIN
+    INSERT INTO log VALUES('DELETE OF t4', old.rowid, old.i, old.t);
+  END;
+  BEGIN;
+}
+set list {}
+for {set ii 1} {$ii < 10000} {incr ii} {
+  lappend list $ii [number_name $ii]
+}
+set script {
+  foreach {ii name} $::list {
+    db eval {INSERT INTO t4 VALUES(NULL, $ii, $name)}
+  }
+}
+speed_trial_tcl speed4p-trigger1 10000 stmt $script
+
+set list {}
+for {set ii 1} {$ii < 20000} {incr ii 2} {
+  set ii2 [expr {$ii*2}]
+  lappend list $ii $ii2 [number_name $ii2]
+}
+set script {
+  foreach {ii ii2 name} $::list {
+    db eval {
+      UPDATE t4 SET i = $ii2, t = $name WHERE rowid = $ii;
+    }
+  }
+}
+speed_trial_tcl speed4p-trigger2 10000 stmt $script
+
+set script {
+  for {set ii 1} {$ii < 20000} {incr ii 2} {
+    db eval {DELETE FROM t4 WHERE rowid = $ii}
+  }
+}
+speed_trial_tcl speed4p-trigger3 10000 stmt $script
+execsql {COMMIT}
+
+# The following block contains the same tests as the above block that
+# tests triggers, with one crucial difference: no triggers are defined.
+# So the difference in speed between these tests and the preceding ones
+# is the amount of time taken to compile and execute the trigger programs.
+#
+execsql {
+  DROP TABLE t4;
+  DROP TABLE log;
+  VACUUM;
+  CREATE TABLE t4(rowid INTEGER PRIMARY KEY, i INTEGER, t TEXT);
+  BEGIN;
+}
+set list {}
+for {set ii 1} {$ii < 10000} {incr ii} {
+  lappend list $ii [number_name $ii]
+}
+set script {
+  foreach {ii name} $::list {
+    db eval {INSERT INTO t4 VALUES(NULL, $ii, $name);}
+  }
+}
+speed_trial_tcl speed4p-notrigger1 10000 stmt $script
+
+set list {}
+for {set ii 1} {$ii < 20000} {incr ii 2} {
+  set ii2 [expr {$ii*2}]
+  lappend list $ii $ii2 [number_name $ii2]
+}
+set script {
+  foreach {ii ii2 name} $::list {
+    db eval {
+      UPDATE t4 SET i = $ii2, t = $name WHERE rowid = $ii;
+    }
+  }
+}
+speed_trial_tcl speed4p-notrigger2 10000 stmt $script
+
+set script {
+  for {set ii 1} {$ii < 20000} {incr ii 2} {
+    db eval {DELETE FROM t4 WHERE rowid = $ii}
+  }
+}
+speed_trial_tcl speed4p-notrigger3 10000 stmt $script
+execsql {COMMIT}
+
+speed_trial_summary speed4
+finish_test