Skip to content

Commit

Permalink
* Add benchmarks for storage engines
Browse files Browse the repository at this point in the history
  • Loading branch information
smtlaissezfaire committed Jan 4, 2009
1 parent fb4025e commit 9c3d7e8
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
10 changes: 10 additions & 0 deletions benchmarks/storage_engines.benchmark
@@ -0,0 +1,10 @@
-- create_table(:innodb, {:force=>true, :options=>"ENGINE=InnoDB"})
-> 0.0237s
-- create_table(:myisam, {:force=>true, :options=>"ENGINE=MyISAM"})
-> 0.0030s
-- create_table(:archive, {:force=>true, :options=>"ENGINE=Archive"})
-> 0.0029s
user system total real
inserts with innodb storage engine 9.240000 0.870000 10.110000 ( 18.102314)
inserts with myisam storage engine 5.890000 0.490000 6.380000 ( 8.401665)
inserts with archive storage engine 5.900000 0.480000 6.380000 ( 8.426003)
64 changes: 64 additions & 0 deletions benchmarks/storage_engines.rb
@@ -0,0 +1,64 @@
require "rubygems"
require "benchmark"
require "active_support"
require "active_record"

TIMES = 10_000

ActiveRecord::Base.establish_connection({
:adapter => 'mysql',
:database => 'query_analyzer_test',
:user => "root",
:password => ""
})

ActiveRecord::Schema.define do

create_table :innodb, :force => true, :options => 'ENGINE=InnoDB' do |t|
t.string :foo
end

create_table :myisam, :force => true, :options => 'ENGINE=MyISAM' do |t|
t.string :foo
end

create_table :archive, :force => true, :options => 'ENGINE=Archive' do |t|
t.string :foo
end

end

class InnoDB < ActiveRecord::Base
set_table_name :innodb
end

class MyISAM < ActiveRecord::Base
set_table_name :myisam
end

class Archive < ActiveRecord::Base
set_table_name :archive
end

class String
def self.random(length=10)
chars = ("a".."z").to_a
string = ""
1.upto(length) { |i| string << chars[rand(chars.size-1)]}
return string
end
end

Benchmark.bm do |b|
b.report "inserts with innodb storage engine" do
TIMES.times { InnoDB.create!(:foo => String.random) }
end

b.report "inserts with myisam storage engine" do
TIMES.times { MyISAM.create!(:foo => String.random) }
end

b.report "inserts with archive storage engine" do
TIMES.times { Archive.create!(:foo => String.random) }
end
end

0 comments on commit 9c3d7e8

Please sign in to comment.