2 set testdir
[file join [file dirname
$argv0] .. .. test
]
3 source $testdir/tester.tcl
13 puts "Generating $NROW rows of data..."
15 for {set ii
0} {$ii < $NROW} {incr ii
} {
16 set x1
[expr {rand
()*1000}]
17 set x2
[expr {$x1+rand
()*50}]
18 set y1
[expr {rand
()*1000}]
19 set y2
[expr {$y1+rand
()*50}]
20 lappend data
$x1 $x2 $y1 $y2
22 puts "Finished generating data"
25 set sql1
{CREATE TABLE btree
(ii INTEGER PRIMARY KEY
, x1
, x2
, y1
, y2
)}
26 set sql2
{CREATE VIRTUAL TABLE rtree USING rtree
(ii
, x1
, x2
, y1
, y2
)}
27 puts "Creating tables:"
33 db
eval "pragma cache_size=100"
35 puts -nonewline "Inserting into btree... "
37 set btree_time
[time {db transaction
{
39 foreach {x1 x2 y1 y2
} $data {
40 db
eval {INSERT INTO btree VALUES
($ii, $x1, $x2, $y1, $y2)}
46 puts -nonewline "Inserting into rtree... "
48 set rtree_time
[time {db transaction
{
50 foreach {x1 x2 y1 y2
} $data {
52 db
eval {INSERT INTO rtree VALUES
($ii, $x1, $x2, $y1, $y2)}
58 puts -nonewline "Selecting from btree... "
60 set btree_select_time
[time {
61 foreach {x1 x2 y1 y2
} [lrange $data 0 [expr $NQUERY*4-1]] {
62 db
eval {SELECT
* FROM btree WHERE x1
<$x1 AND x2
>$x2 AND y1
<$y1 AND y2
>$y2}
65 puts "$btree_select_time"
67 puts -nonewline "Selecting from rtree... "
69 set rtree_select_time
[time {
70 foreach {x1 x2 y1 y2
} [lrange $data 0 [expr $NQUERY*4-1]] {
71 db
eval {SELECT
* FROM rtree WHERE x1
<$x1 AND x2
>$x2 AND y1
<$y1 AND y2
>$y2}
74 puts "$rtree_select_time"