From 10ee0256473fd0ca9406fb37ed79ab6117baa37b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lourens=20Naud=C3=A9?= Date: Sun, 8 Aug 2010 23:49:44 +0100 Subject: [PATCH] Benchmark for select VS rb_thread_select --- Rakefile | 4 ++-- benchmark/thread_alone.rb | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 benchmark/thread_alone.rb diff --git a/Rakefile b/Rakefile index ad0a387..60fb02a 100644 --- a/Rakefile +++ b/Rakefile @@ -48,6 +48,6 @@ namespace :bench do define_bench_task :query_without_mysql_casting define_bench_task :sequel define_bench_task :allocations -end -# Load custom tasks + define_bench_task :thread_alone +end# Load custom tasks Dir['tasks/*.rake'].sort.each { |f| load f } diff --git a/benchmark/thread_alone.rb b/benchmark/thread_alone.rb new file mode 100644 index 0000000..c6b4c1e --- /dev/null +++ b/benchmark/thread_alone.rb @@ -0,0 +1,20 @@ +# encoding: UTF-8 +$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') + +require 'rubygems' +require 'benchmark' +require 'mysql2' + +iterations = 1000 +client = Mysql2::Client.new(:host => "localhost", :username => "root", :database => "test") +query = lambda{ iterations.times{ client.query("SELECT mysql2_test.* FROM mysql2_test") } } +Benchmark.bmbm do |x| + x.report('select') do + query.call + end + x.report('rb_thread_select') do + thread = Thread.new{ sleep(10) } + query.call + thread.kill + end +end \ No newline at end of file