Add speed4.test, with some speed tests for triggers, sub-selects, views and joins. (CVS 4504)

FossilOrigin-Name: 3e3475b9e0f996841aa40419693c7c3eaa6c71aa
This commit is contained in:
danielk1977 2007-10-23 10:25:30 +00:00
parent 191fadcf23
commit 0d6e7a00d6
4 changed files with 242 additions and 8 deletions

View File

@ -1,5 +1,5 @@
C Fix\san\serror\smessage\sin\sthe\stcl\sinterface.\s(CVS\s4503)
D 2007-10-23T08:17:48
C Add\sspeed4.test,\swith\ssome\sspeed\stests\sfor\striggers,\ssub-selects,\sviews\sand\sjoins.\s(CVS\s4504)
D 2007-10-23T10:25:30
F Makefile.in 30c7e3ba426ddb253b8ef037d1873425da6009a8
F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@ -392,7 +392,7 @@ F test/pragma2.test 5364893491b9231dd170e3459bfc2e2342658b47
F test/printf.test 6bf1a86c6a1e45536f72d782bf44c8e3c76510f8
F test/progress.test 5b075c3c790c7b2a61419bc199db87aaf48b8301 x
F test/ptrchng.test 38ae1806833d72d9a81a6121322e274f24937e18
F test/quick.test 47605260d370844596ae5b52cdcf50d70525e7ee
F test/quick.test fa4e9d57956d05d024689e12ec7b40b3f0224d44
F test/quote.test 215897dbe8de1a6f701265836d6601cc6ed103e6
F test/rdonly.test b34db316525440d3b42c32e83942c02c37d28ef0
F test/reindex.test 38b138abe36bf9a08c791ed44d9f76cd6b97b78b
@ -420,6 +420,7 @@ F test/sort.test 0e4456e729e5a92a625907c63dcdedfbe72c5dc5
F test/speed1.test 22e1b27af0683ed44dcd2f93ed817a9c3e65084a
F test/speed2.test 53177056baf6556dcbdcf032bbdfc41c1aa74ded
F test/speed3.test e312d7e442a5047d730569fdae2ba99bc94e1a13
F test/speed4.test 20d8ea20bea3ca09c3ef3b5ec820a17e58e132cb
F test/sqllimits1.test 3b08a538c9828041a5c1454293594d922602044d
F test/subquery.test 8203f85db56ba022a57a0589890090c8feed4e59
F test/subselect.test 974e87f8fc91c5f00dd565316d396a5a6c3106c4
@ -583,7 +584,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P aef7720e0bb49d52332ddebe6f698feb926ef7d7
R 86d6f1c31cfe170f6b4b00de0d246413
P 2449e08069ef830f119203c4a3737d6756e73c63
R 9ff5bb31431b0085b77a736c1e69245b
U danielk1977
Z ed043c1e2caea20587e74619c1ec5335
Z 15cc286b9726040cda03d092104a36be

View File

@ -1 +1 @@
2449e08069ef830f119203c4a3737d6756e73c63
3e3475b9e0f996841aa40419693c7c3eaa6c71aa

View File

@ -6,7 +6,7 @@
#***********************************************************************
# This file runs all tests.
#
# $Id: quick.test,v 1.64 2007/09/14 16:20:01 danielk1977 Exp $
# $Id: quick.test,v 1.65 2007/10/23 10:25:30 danielk1977 Exp $
proc lshift {lvar} {
upvar $lvar l
@ -65,6 +65,7 @@ set EXCLUDE {
soak.test
speed1.test
speed2.test
speed4.test
sqllimits1.test
thread001.test

232
test/speed4.test Normal file
View File

@ -0,0 +1,232 @@
# 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: speed4.test,v 1.1 2007/10/23 10:25:30 danielk1977 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:
#
# speed4-join1: Join three tables using IPK index.
# speed4-join2: Join three tables using an index.
# speed4-join3: Join two tables without an index.
#
# speed4-view1: Querying a view.
# speed4-table1: Same queries as in speed4-view1, but run directly against
# the tables for comparison purposes.
#
# speed4-subselect1: A SELECT statement that uses many sub-queries..
#
# speed4-trigger1: An INSERT statement that fires a trigger.
# speed4-trigger2: An UPDATE statement that fires a trigger.
# speed4-trigger3: A DELETE statement that fires a trigger.
# speed4-notrigger1: Same operation as trigger1, but without the trigger.
# speed4-notrigger2: " trigger2 "
# speed4-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 speed4-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 speed4-join2 50000 row $sql
# Run 10000 simple queries against the views.
set sql ""
for {set ii 1} {$ii < 10000} {incr ii} {
append sql "SELECT * FROM v[expr {($ii%3)+1}] WHERE rowid = [expr {$ii*3}];"
}
speed_trial speed4-view1 10000 stmt $sql
# 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 sql ""
for {set ii 1} {$ii < 10000} {incr ii} {
append sql "SELECT t FROM t[expr {($ii%3)+1}] WHERE rowid = [expr {$ii*3}];"
}
speed_trial speed4-table1 10000 stmt $sql
# Run a SELECT that uses sub-queries 10000 times. A total of 30000 sub-selects.
#
set sql ""
for {set ii 1} {$ii < 10000} {incr ii} {
append sql "
SELECT (SELECT t FROM t1 WHERE rowid = [expr {$ii*3}]),
(SELECT t FROM t2 WHERE rowid = [expr {$ii*3}]),
(SELECT t FROM t3 WHERE rowid = [expr {$ii*3}])
;"
}
speed_trial speed4-subselect1 10000 stmt $sql
# 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 sql ""
for {set ii 1} {$ii < 10000} {incr ii} {
append sql "INSERT INTO t4 VALUES(NULL, $ii, '[number_name $ii]');"
}
speed_trial speed4-trigger1 10000 stmt $sql
set sql ""
for {set ii 1} {$ii < 20000} {incr ii 2} {
set ii2 [expr {$ii*2}]
append sql "
UPDATE t4 SET i = $ii2, t = '[number_name $ii2]' WHERE rowid = $ii;
"
}
speed_trial speed4-trigger2 10000 stmt $sql
set sql ""
for {set ii 1} {$ii < 20000} {incr ii 2} {
append sql "DELETE FROM t4 WHERE rowid = $ii;"
}
speed_trial speed4-trigger3 10000 stmt $sql
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 sql ""
for {set ii 1} {$ii < 10000} {incr ii} {
append sql "INSERT INTO t4 VALUES(NULL, $ii, '[number_name $ii]');"
}
speed_trial speed4-notrigger1 10000 stmt $sql
set sql ""
for {set ii 1} {$ii < 20000} {incr ii 2} {
set ii2 [expr {$ii*2}]
append sql "
UPDATE t4 SET i = $ii2, t = '[number_name $ii2]' WHERE rowid = $ii;
"
}
speed_trial speed4-notrigger2 10000 stmt $sql
set sql ""
for {set ii 1} {$ii < 20000} {incr ii 2} {
append sql "DELETE FROM t4 WHERE rowid = $ii;"
}
speed_trial speed4-notrigger3 10000 stmt $sql
execsql {COMMIT}
speed_trial_summary speed4
finish_test