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
|
$:.unshift "../lib", "../ext/sqlite3_api"
require 'sqlite3'
require 'benchmark'
N = 1000
$VERBOSE=nil
puts "database creation..."
Benchmark.bm( 7 ) do |x|
x.report('dl') do
N.times do
File.delete "test.db" rescue nil
SQLite3::Database.open( "test.db", :driver => "DL" ).close
end
end
x.report('native') do
N.times do
File.delete "test.db" rescue nil
SQLite3::Database.open( "test.db", :driver => "Native" ).close
end
end
end
File.delete "test.db" rescue nil
SQLite3::Database.open( "test.db" ).close
puts
puts "database open..."
Benchmark.bm( 7 ) do |x|
x.report('dl') do
N.times do
SQLite3::Database.open( "test.db", :driver => "DL" ).close
end
end
x.report('native') do
N.times do
SQLite3::Database.open( "test.db", :driver => "Native" ).close
end
end
end
File.delete "test.db" rescue nil
dl = SQLite3::Database.open( "test-dl.db", :driver => "DL" )
native = SQLite3::Database.open( "test-native.db", :driver => "Native" )
dl.execute "create table foo (a,b)"
native.execute "create table foo (a,b)"
puts
puts "insertions"
Benchmark.bm( 7 ) do |x|
x.report('dl') do
dl.transaction do
N.times do |i|
dl.execute "insert into foo values (#{i}, #{i+1})"
end
end
end
x.report('native') do
native.transaction do
N.times do |i|
native.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('dl') do
dl.transaction do
dl.prepare "insert into foo values (?,?)" do |stmt|
N.times { |i| stmt.execute i, i+1 }
end
end
end
x.report('native') do
native.transaction do
native.prepare( "insert into foo values (?,?)" ) do |stmt|
N.times { |i| stmt.execute i, i+1 }
end
end
end
end
dl.close
native.close
File.delete "test-dl.db" rescue nil
File.delete "test-native.db" rescue nil
dl = SQLite3::Database.open( "test-dl.db", :driver => "DL" )
native = SQLite3::Database.open( "test-native.db", :driver => "Native" )
dl.execute "create table foo (a,b)"
dl.execute "insert into foo values (1,2)"
dl.execute "insert into foo values (3,4)"
dl.execute "insert into foo values (5,6)"
native.execute "create table foo (a,b)"
native.execute "insert into foo values (1,2)"
native.execute "insert into foo values (3,4)"
native.execute "insert into foo values (5,6)"
puts
puts "queries"
Benchmark.bm( 7 ) do |x|
x.report('dl') do
N.times do
dl.execute "select * from foo"
end
end
x.report('native') do
N.times do
native.execute "select * from foo"
end
end
end
dl.close
native.close
File.delete "test-dl.db" rescue nil
File.delete "test-native.db" rescue nil
|