3 # Run this script using TCLSH to do a speed comparison between
4 # various versions of SQLite and PostgreSQL and MySQL
10 proc runtest
{title
} {
12 set sqlfile test
$cnt.sql
13 puts "<h2>Test $cnt: $title</h2>"
15 set fd
[open $sqlfile r
]
16 set sql
[string trim
[read $fd [file size
$sqlfile]]]
18 set sx
[split $sql \n]
22 for {set i
0} {$i<3} {incr i
} {append sql
[lindex $sx $i]<br
>\n}
23 append sql
"<i>... [expr {$n-6}] lines omitted</i><br>\n"
24 for {set i
[expr {$n-3}]} {$i<$n} {incr i
} {
25 append sql
[lindex $sx $i]<br
>\n
28 regsub -all \n [string trim
$sql] <br
> sql
32 puts "</blockquote><table border=0 cellpadding=0 cellspacing=0>"
33 set format {<tr
><td
>%s
</td
><td align
="right"> 
; 
; 
;%.3f
</td
></tr
>}
35 exec sync
; after $delay;
36 set t
[time "exec psql drh <$sqlfile" 1]
37 set t
[expr {[lindex $t 0]/1000000.0}]
38 puts [format $format PostgreSQL
: $t]
39 exec sync
; after $delay;
40 set t
[time "exec mysql -f drh <$sqlfile" 1]
41 set t
[expr {[lindex $t 0]/1000000.0}]
42 puts [format $format MySQL
: $t]
43 # set t [time "exec ./sqlite232 s232.db <$sqlfile" 1]
44 # set t [expr {[lindex $t 0]/1000000.0}]
45 # puts [format $format {SQLite 2.3.2:} $t]
46 # set t [time "exec ./sqlite-100 s100.db <$sqlfile" 1]
47 # set t [expr {[lindex $t 0]/1000000.0}]
48 # puts [format $format {SQLite 2.4 (cache=100):} $t]
49 exec sync
; after $delay;
50 set t
[time "exec ./sqlite240 s2k.db <$sqlfile" 1]
51 set t
[expr {[lindex $t 0]/1000000.0}]
52 puts [format $format {SQLite
2.4:} $t]
53 exec sync
; after $delay;
54 set t
[time "exec ./sqlite240 sns.db <$sqlfile" 1]
55 set t
[expr {[lindex $t 0]/1000000.0}]
56 puts [format $format {SQLite
2.4 (nosync
):} $t]
57 # set t [time "exec ./sqlite-t1 st1.db <$sqlfile" 1]
58 # set t [expr {[lindex $t 0]/1000000.0}]
59 # puts [format $format {SQLite 2.4 (test):} $t]
63 # Initialize the environment
66 catch {exec /bin
/sh
-c {rm
-f s
*.db
}}
67 set fd
[open clear.sql w
]
73 catch {exec psql drh
<clear.sql
}
74 catch {exec mysql drh
<clear.sql
}
75 set fd
[open 2kinit.sql w
]
77 PRAGMA default_cache_size
=2000;
78 PRAGMA default_synchronous
=on
;
81 exec .
/sqlite240 s2k.db
<2kinit.sql
82 exec .
/sqlite-t1 st1.db
<2kinit.sql
83 set fd
[open nosync-init.sql w
]
85 PRAGMA default_cache_size
=2000;
86 PRAGMA default_synchronous
=off
;
89 exec .
/sqlite240 sns.db
<nosync-init.sql
90 set ones
{zero one two three four five six seven eight nine
91 ten eleven twelve thirteen fourteen fifteen sixteen seventeen
93 set tens
{{} ten twenty thirty forty fifty sixty seventy eighty ninety
}
94 proc number_name
{n
} {
96 set txt
"[number_name [expr {$n/1000}]] thousand"
97 set n
[expr {$n%1000}]
102 append txt
" [lindex $::ones [expr {$n/100}]] hundred"
103 set n
[expr {$n%100}]
106 append txt
" [lindex $::tens [expr {$n/10}]]"
110 append txt
" [lindex $::ones $n]"
112 set txt
[string trim
$txt]
113 if {$txt==""} {set txt zero
}
118 set fd
[open test
$cnt.sql w
]
120 puts $fd "CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100));"
121 for {set i
1} {$i<=25000} {incr i
} {
122 set r
[expr {int
(rand
()*500000)}]
123 puts $fd "INSERT INTO t1 VALUES($i,$r,'[number_name $r]');"
127 runtest
{25000 INSERTs in a transaction
}
130 set fd
[open test
$cnt.sql w
]
131 puts $fd "DELETE FROM t1;"
133 runtest
{DELETE everything
}
136 set fd
[open test
$cnt.sql w
]
138 for {set i
1} {$i<=25000} {incr i
} {
139 set r
[expr {int
(rand
()*500000)}]
140 puts $fd "INSERT INTO t1 VALUES($i,$r,'[number_name $r]');"
144 runtest
{25000 INSERTs in a transaction
}
147 set fd
[open test
$cnt.sql w
]
148 puts $fd "DELETE FROM t1;"
150 runtest
{DELETE everything
}
153 set fd
[open test
$cnt.sql w
]
155 for {set i
1} {$i<=25000} {incr i
} {
156 set r
[expr {int
(rand
()*500000)}]
157 puts $fd "INSERT INTO t1 VALUES($i,$r,'[number_name $r]');"
161 runtest
{25000 INSERTs in a transaction
}
164 set fd
[open test
$cnt.sql w
]
165 puts $fd "DELETE FROM t1;"
167 runtest
{DELETE everything
}
170 set fd
[open test
$cnt.sql w
]
172 for {set i
1} {$i<=25000} {incr i
} {
173 set r
[expr {int
(rand
()*500000)}]
174 puts $fd "INSERT INTO t1 VALUES($i,$r,'[number_name $r]');"
178 runtest
{25000 INSERTs in a transaction
}
181 set fd
[open test
$cnt.sql w
]
182 puts $fd "DELETE FROM t1;"
184 runtest
{DELETE everything
}
187 set fd
[open test
$cnt.sql w
]
189 for {set i
1} {$i<=25000} {incr i
} {
190 set r
[expr {int
(rand
()*500000)}]
191 puts $fd "INSERT INTO t1 VALUES($i,$r,'[number_name $r]');"
195 runtest
{25000 INSERTs in a transaction
}
198 set fd
[open test
$cnt.sql w
]
199 puts $fd "DELETE FROM t1;"
201 runtest
{DELETE everything
}
204 set fd
[open test
$cnt.sql w
]
205 puts $fd {DROP TABLE t1
;}