Created
June 25, 2010 11:21
-
-
Save gr4y/452728 to your computer and use it in GitHub Desktop.
Benchmark with ActiveRecord and paper_trail
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 'test_helper' | |
require 'benchmark' | |
class ArticlesTest < ActiveSupport::TestCase | |
# Replace this with your real tests. | |
test "benchmark" do | |
Benchmark.bm do |b| | |
# create an article with paper_trail | |
b.report("create") do | |
Article.paper_trail_on | |
100.times do | |
@article = Article.create(:title=>"ruby", :content=>"i like ruby") | |
end | |
end | |
# update article with paper_trail | |
b.report("update") do | |
Article.paper_trail_on | |
100.times do | |
@article.update_attributes!(:content=>"i love ruby") | |
@article.save | |
end | |
end | |
# create an article without paper_trail | |
b.report("create without paper_trail") do | |
Article.paper_trail_off | |
100.times do | |
@article_wo = Article.create(:title=>"ruby", :content=>"i like ruby") | |
end | |
end | |
# update article without paper_trail | |
b.report("update without paper_trail") do | |
Article.paper_trail_off | |
100.times do | |
@article_wo.update_attributes!(:content=>"i love ruby") | |
@article_wo.save | |
end | |
end | |
end | |
end | |
end |
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
user system total real | |
create 0.680000 0.080000 0.760000 ( 1.613092) | |
update 0.250000 0.040000 0.290000 ( 0.945468) | |
create without paper_trail 0.260000 0.050000 0.310000 ( 0.886467) | |
update without paper_trail 0.160000 0.040000 0.200000 ( 0.962437) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment