Skip to content
Browse files

* Add benchmarks for storage engines

  • Loading branch information...
1 parent fb4025e commit 9c3d7e84ccb96ec52b554f6f72232e9ee0360e67 @smtlaissezfaire committed Jan 4, 2009
Showing with 74 additions and 0 deletions.
  1. +10 −0 benchmarks/storage_engines.benchmark
  2. +64 −0 benchmarks/storage_engines.rb
View
10 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)
View
64 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.
Something went wrong with that request. Please try again.