1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
require 'benchmark'
N = 1000
$VERBOSE=nil
puts "file require"
Benchmark.bm( 7 ) do |x|
x.report('sqlite') do
N.times do
$".delete_if { |i| i =~ /sqlite/ }
require 'sqlite'
end
end
x.report('sqlite3') do
N.times do
$".delete_if { |i| i =~ /sqlite3/ }
require 'sqlite3'
end
end
end
puts
puts "database creation..."
Benchmark.bm( 7 ) do |x|
x.report('sqlite') do
N.times do
File.delete "test.db" rescue nil
SQLite::Database.open( "test.db" ).close
end
end
x.report('sqlite3') do
N.times do
File.delete "test.db" rescue nil
SQLite3::Database.open( "test.db" ).close
end
end
end
File.delete "test.db" rescue nil
SQLite::Database.open( "test.db" ).close
SQLite3::Database.open( "test3.db" ).close
puts
puts "database open..."
Benchmark.bm( 7 ) do |x|
x.report('sqlite') do
N.times do
SQLite::Database.open( "test.db" ).close
end
end
x.report('sqlite3') do
N.times do
SQLite3::Database.open( "test3.db" ).close
end
end
end
File.delete "test.db" rescue nil
File.delete "test3.db" rescue nil
db = SQLite::Database.open( "test.db" )
db3 = SQLite3::Database.open( "test3.db" )
db.execute "create table foo (a,b)"
db3.execute "create table foo (a,b)"
puts
puts "insertions"
Benchmark.bm( 7 ) do |x|
x.report('sqlite') do
db.transaction do
N.times do |i|
db.execute "insert into foo values (#{i}, #{i+1})"
end
end
end
x.report('sqlite3') do
db3.transaction do
N.times do |i|
db3.execute "insert into foo values (#{i}, #{i+1})"
end
end
end
end
puts
puts "insertions using prepared statement"
Benchmark.bm( 7 ) do |x|
x.report('sqlite') do
db.transaction do
stmt = db.prepare "insert into foo values (?,?)"
N.times { |i| stmt.execute i, i+1 }
end
end
x.report('sqlite3') do
db3.transaction do
db3.prepare( "insert into foo values (?,?)" ) do |stmt|
N.times { |i| stmt.execute i, i+1 }
end
end
end
end
db.close
db3.close
File.delete "test.db" rescue nil
File.delete "test3.db" rescue nil
db = SQLite::Database.open( "test.db" )
db3 = SQLite3::Database.open( "test3.db" )
db.execute "create table foo (a,b)"
db.execute "insert into foo values (1,2)"
db.execute "insert into foo values (3,4)"
db.execute "insert into foo values (5,6)"
db3.execute "create table foo (a,b)"
db3.execute "insert into foo values (1,2)"
db3.execute "insert into foo values (3,4)"
db3.execute "insert into foo values (5,6)"
puts
puts "queries"
Benchmark.bm( 7 ) do |x|
x.report('sqlite') do
N.times do
db.execute "select * from foo"
end
end
x.report('sqlite3') do
N.times do
db3.execute "select * from foo"
end
end
end
db.close
db3.close
File.delete "test.db" rescue nil
File.delete "test3.db" rescue nil
|