rtree_perf.tcl 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. set testdir [file join [file dirname $argv0] .. .. test]
  2. source $testdir/tester.tcl
  3. ifcapable !rtree {
  4. finish_test
  5. return
  6. }
  7. set NROW 10000
  8. set NQUERY 500
  9. puts "Generating $NROW rows of data..."
  10. set data [list]
  11. for {set ii 0} {$ii < $NROW} {incr ii} {
  12. set x1 [expr {rand()*1000}]
  13. set x2 [expr {$x1+rand()*50}]
  14. set y1 [expr {rand()*1000}]
  15. set y2 [expr {$y1+rand()*50}]
  16. lappend data $x1 $x2 $y1 $y2
  17. }
  18. puts "Finished generating data"
  19. set sql1 {CREATE TABLE btree(ii INTEGER PRIMARY KEY, x1, x2, y1, y2)}
  20. set sql2 {CREATE VIRTUAL TABLE rtree USING rtree(ii, x1, x2, y1, y2)}
  21. puts "Creating tables:"
  22. puts " $sql1"
  23. puts " $sql2"
  24. db eval $sql1
  25. db eval $sql2
  26. db eval "pragma cache_size=100"
  27. puts -nonewline "Inserting into btree... "
  28. flush stdout
  29. set btree_time [time {db transaction {
  30. set ii 1
  31. foreach {x1 x2 y1 y2} $data {
  32. db eval {INSERT INTO btree VALUES($ii, $x1, $x2, $y1, $y2)}
  33. incr ii
  34. }
  35. }}]
  36. puts "$btree_time"
  37. puts -nonewline "Inserting into rtree... "
  38. flush stdout
  39. set rtree_time [time {db transaction {
  40. set ii 1
  41. foreach {x1 x2 y1 y2} $data {
  42. incr ii
  43. db eval {INSERT INTO rtree VALUES($ii, $x1, $x2, $y1, $y2)}
  44. }
  45. }}]
  46. puts "$rtree_time"
  47. puts -nonewline "Selecting from btree... "
  48. flush stdout
  49. set btree_select_time [time {
  50. foreach {x1 x2 y1 y2} [lrange $data 0 [expr $NQUERY*4-1]] {
  51. db eval {SELECT * FROM btree WHERE x1<$x1 AND x2>$x2 AND y1<$y1 AND y2>$y2}
  52. }
  53. }]
  54. puts "$btree_select_time"
  55. puts -nonewline "Selecting from rtree... "
  56. flush stdout
  57. set rtree_select_time [time {
  58. foreach {x1 x2 y1 y2} [lrange $data 0 [expr $NQUERY*4-1]] {
  59. db eval {SELECT * FROM rtree WHERE x1<$x1 AND x2>$x2 AND y1<$y1 AND y2>$y2}
  60. }
  61. }]
  62. puts "$rtree_select_time"