-
-
Save jhawthorn/ae84ee2723ff4930344778cfe40205a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "sqlite3" | |
require "benchmark" | |
FileUtils.rm_f("test.db") | |
def open_db | |
db = SQLite3::Database.new "test.db" | |
end | |
def create_db | |
db = open_db | |
db.execute "BEGIN" | |
# Based on tool/speedtest.tcl from sqlite | |
db.execute <<-SQL | |
create table t2 (a INTEGER, b INTEGER, c VARCHAR(100)); | |
SQL | |
1.upto(25000) do |i| | |
r = rand(500000) | |
db.execute "INSERT INTO t2 VALUES(#{i},#{r},'[number_name #{r}]');" | |
end | |
db.execute "COMMIT" | |
end | |
def run_test(db = open_db) | |
i = 0 | |
while i < 10000 | |
sql = <<~SQL | |
SELECT count(*), avg(b) FROM t2 WHERE b>=#{i} AND b<#{i + 1000}; | |
SQL | |
db.execute(sql) | |
i += 100 | |
end | |
end | |
def run_tests(n=10, threaded: false) | |
if threaded | |
n.times.map { Thread.new { run_test } }.map(&:join) | |
else | |
n.times { run_test } | |
end | |
end | |
create_db | |
run_test | |
puts "single threaded:" | |
puts Benchmark.realtime { run_tests(threaded: false) } | |
puts "multi threaded:" | |
puts Benchmark.realtime { run_tests(threaded: true) } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sqlite3-ruby master
With (incomplete, hacky) GVL release patch: