Created
March 2, 2010 13:41
-
-
Save amasses/319508 to your computer and use it in GitHub Desktop.
Ruby files used for benchmarking
This file contains hidden or 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 'rubygems' | |
| require 'active_support' | |
| require 'active_support/core_ext' | |
| require 'ohm' | |
| require 'mongo_mapper' | |
| require 'benchmark' | |
| require 'dm-core' | |
| require 'model1' | |
| require 'model2' | |
| require 'model3' | |
| # Setup | |
| MongoMapper.connection = Mongo::Connection.new("localhost") | |
| MongoMapper.database = "benchmarking" | |
| Ohm.connect {} | |
| DataMapper.setup(:default, "mysql://root@localhost/benchmarking") | |
| Model3.auto_migrate! | |
| klasses = [Model1, Model2, Model3] | |
| klasses.each do |klass| | |
| if klass==Model1 | |
| puts "MongoMapper" | |
| elsif klass==Model2 | |
| puts "Ohm/Redis" | |
| else | |
| puts "MySQL/Datamapper" | |
| end | |
| Benchmark.bm do |x| | |
| x.report("Create") do | |
| 10_000.times { | |
| person = klass.create({ | |
| :first_name => 'John', | |
| :last_name => 'Nunemaker', | |
| :age => 27, | |
| :born_at => Time.mktime(1981, 11, 25, 2, 30), | |
| :active => true, | |
| :fav_colors => %w(red green blue) | |
| }) | |
| } | |
| end | |
| x.report("Read") do | |
| klass.all.each do |y| | |
| id = y.id | |
| end | |
| end | |
| x.report("Update") do | |
| klass.all.each do |y| | |
| y.first_name = "Charlie" | |
| y.save | |
| end | |
| end | |
| x.report("Destroy") do | |
| klass.all.each do |y| | |
| if klass == Model3 | |
| y.destroy | |
| else | |
| y.delete | |
| end | |
| end | |
| end | |
| end | |
| end |
This file contains hidden or 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 'active_support' | |
| class Model1 | |
| include MongoMapper::Document | |
| key :first_name, String | |
| key :last_name, String | |
| key :age, Integer | |
| key :born_at, Time | |
| key :active, Boolean | |
| key :fav_colors, Array | |
| end |
This file contains hidden or 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
| class Model2 < Ohm::Model | |
| attribute :first_name | |
| attribute :last_name | |
| attribute :age | |
| attribute :born_at | |
| attribute :active | |
| attribute :fav_colors | |
| end |
This file contains hidden or 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
| class Model3 | |
| include DataMapper::Resource | |
| property :id, Serial | |
| property :first_name, String | |
| property :last_name, String | |
| property :age, Integer | |
| property :born_at, DateTime | |
| property :active, Boolean | |
| property :fav_colors, Text | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment