2 #pragma ident "%Z%%M% %I% %E% SMI"
6 # Run this script using TCLSH to do a speed comparison between
7 # various versions of SQLite and PostgreSQL and MySQL
13 proc runtest
{title
} {
15 set sqlfile test
$cnt.sql
16 puts "<h2>Test $cnt: $title</h2>"
18 set fd
[open $sqlfile r
]
19 set sql
[string trim
[read $fd [file size
$sqlfile]]]
21 set sx
[split $sql \n]
25 for {set i
0} {$i<3} {incr i
} {append sql
[lindex $sx $i]<br
>\n}
26 append sql
"<i>... [expr {$n-6}] lines omitted</i><br>\n"
27 for {set i
[expr {$n-3}]} {$i<$n} {incr i
} {
28 append sql
[lindex $sx $i]<br
>\n
31 regsub -all \n [string trim
$sql] <br
> sql
35 puts "</blockquote><table border=0 cellpadding=0 cellspacing=0>"
36 set format {<tr
><td
>%s
</td
><td align
="right"> 
; 
; 
;%.3f
</td
></tr
>}
38 exec sync
; after $delay;
39 set t
[time "exec psql drh <$sqlfile" 1]
40 set t
[expr {[lindex $t 0]/1000000.0}]
41 puts [format $format PostgreSQL
: $t]
42 exec sync
; after $delay;
43 set t
[time "exec mysql -f drh <$sqlfile" 1]
44 set t
[expr {[lindex $t 0]/1000000.0}]
45 puts [format $format MySQL
: $t]
46 # set t [time "exec ./sqlite232 s232.db <$sqlfile" 1]
47 # set t [expr {[lindex $t 0]/1000000.0}]
48 # puts [format $format {SQLite 2.3.2:} $t]
49 # set t [time "exec ./sqlite-100 s100.db <$sqlfile" 1]
50 # set t [expr {[lindex $t 0]/1000000.0}]
51 # puts [format $format {SQLite 2.4 (cache=100):} $t]
52 exec sync
; after $delay;
53 set t
[time "exec ./sqlite240 s2k.db <$sqlfile" 1]
54 set t
[expr {[lindex $t 0]/1000000.0}]
55 puts [format $format {SQLite
2.4:} $t]
56 exec sync
; after $delay;
57 set t
[time "exec ./sqlite240 sns.db <$sqlfile" 1]
58 set t
[expr {[lindex $t 0]/1000000.0}]
59 puts [format $format {SQLite
2.4 (nosync
):} $t]
60 # set t [time "exec ./sqlite-t1 st1.db <$sqlfile" 1]
61 # set t [expr {[lindex $t 0]/1000000.0}]
62 # puts [format $format {SQLite 2.4 (test):} $t]
66 # Initialize the environment
69 catch {exec /bin
/sh
-c {rm
-f s
*.db
}}
70 set fd
[open clear.sql w
]
76 catch {exec psql drh
<clear.sql
}
77 catch {exec mysql drh
<clear.sql
}
78 set fd
[open 2kinit.sql w
]
80 PRAGMA default_cache_size
=2000;
81 PRAGMA default_synchronous
=on
;
84 exec .
/sqlite240 s2k.db
<2kinit.sql
85 exec .
/sqlite-t1 st1.db
<2kinit.sql
86 set fd
[open nosync-init.sql w
]
88 PRAGMA default_cache_size
=2000;
89 PRAGMA default_synchronous
=off
;
92 exec .
/sqlite240 sns.db
<nosync-init.sql
93 set ones
{zero one two three four five six seven eight nine
94 ten eleven twelve thirteen fourteen fifteen sixteen seventeen
96 set tens
{{} ten twenty thirty forty fifty sixty seventy eighty ninety
}
97 proc number_name
{n
} {
99 set txt
"[number_name [expr {$n/1000}]] thousand"
100 set n
[expr {$n%1000}]
105 append txt
" [lindex $::ones [expr {$n/100}]] hundred"
106 set n
[expr {$n%100}]
109 append txt
" [lindex $::tens [expr {$n/10}]]"
113 append txt
" [lindex $::ones $n]"
115 set txt
[string trim
$txt]
116 if {$txt==""} {set txt zero
}
121 set fd
[open test
$cnt.sql w
]
123 puts $fd "CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100));"
124 for {set i
1} {$i<=25000} {incr i
} {
125 set r
[expr {int
(rand
()*500000)}]
126 puts $fd "INSERT INTO t1 VALUES($i,$r,'[number_name $r]');"
130 runtest
{25000 INSERTs in a transaction
}
133 set fd
[open test
$cnt.sql w
]
134 puts $fd "DELETE FROM t1;"
136 runtest
{DELETE everything
}
139 set fd
[open test
$cnt.sql w
]
141 for {set i
1} {$i<=25000} {incr i
} {
142 set r
[expr {int
(rand
()*500000)}]
143 puts $fd "INSERT INTO t1 VALUES($i,$r,'[number_name $r]');"
147 runtest
{25000 INSERTs in a transaction
}
150 set fd
[open test
$cnt.sql w
]
151 puts $fd "DELETE FROM t1;"
153 runtest
{DELETE everything
}
156 set fd
[open test
$cnt.sql w
]
158 for {set i
1} {$i<=25000} {incr i
} {
159 set r
[expr {int
(rand
()*500000)}]
160 puts $fd "INSERT INTO t1 VALUES($i,$r,'[number_name $r]');"
164 runtest
{25000 INSERTs in a transaction
}
167 set fd
[open test
$cnt.sql w
]
168 puts $fd "DELETE FROM t1;"
170 runtest
{DELETE everything
}
173 set fd
[open test
$cnt.sql w
]
175 for {set i
1} {$i<=25000} {incr i
} {
176 set r
[expr {int
(rand
()*500000)}]
177 puts $fd "INSERT INTO t1 VALUES($i,$r,'[number_name $r]');"
181 runtest
{25000 INSERTs in a transaction
}
184 set fd
[open test
$cnt.sql w
]
185 puts $fd "DELETE FROM t1;"
187 runtest
{DELETE everything
}
190 set fd
[open test
$cnt.sql w
]
192 for {set i
1} {$i<=25000} {incr i
} {
193 set r
[expr {int
(rand
()*500000)}]
194 puts $fd "INSERT INTO t1 VALUES($i,$r,'[number_name $r]');"
198 runtest
{25000 INSERTs in a transaction
}
201 set fd
[open test
$cnt.sql w
]
202 puts $fd "DELETE FROM t1;"
204 runtest
{DELETE everything
}
207 set fd
[open test
$cnt.sql w
]
208 puts $fd {DROP TABLE t1
;}