Skip to content
Browse files

add benchmark

  • Loading branch information...
1 parent 1787623 commit 8c9009c17960cc7bb68736bf51ed0a724c08cebf @nakajima committed
Showing with 125 additions and 0 deletions.
  1. +86 −0 bench/FINE-A-BENCHMARK.rb
  2. +5 −0 bench/Gemfile
  3. +34 −0 bench/Gemfile.lock
View
86 bench/FINE-A-BENCHMARK.rb
@@ -0,0 +1,86 @@
+# BENCHMARK BECAUSE BRANDON IS A BIG BABY
+#
+# $ bundle install
+# $ bundle exec ruby FINE-A-BENCHMARK.rb
+require "rubygems"
+require "fixjour"
+require "factory_girl"
+require "acts_as_fu"
+
+build_model :users do
+ string :name
+end
+
+build_model :articles do
+ string :title
+ integer :user_id
+ belongs_to :user
+end
+
+Factory.define :user do |user|
+ user.sequence(:name) { |i| "User #{i}" }
+end
+
+Factory.define :article do |article|
+ article.sequence(:title) { |i| "Article #{i}" }
+ article.association :user
+end
+
+Fixjour do
+ define User do |user|
+ user.name = "User #{counter(:user)}"
+ end
+
+ define Article do |article|
+ article.title = "Article #{counter(:article)}"
+ article.user = new_user
+ end
+end
+
+include Fixjour
+
+puts "=" * 80
+puts "Benching new records"
+def bench_new(n)
+ puts "-" * 80
+ puts "Trying #{n} iterations"
+
+ fixjour = Benchmark.realtime {
+ n.times { new_article ; new_user }
+ }
+
+ puts "Fixjour 2: #{fixjour}"
+
+ factory_girl = Benchmark.realtime {
+ n.times { Factory.build(:article) ; Factory.build(:user) }
+ }
+
+ puts "Factory Girl: #{factory_girl}"
+end
+
+bench_new 100
+bench_new 1000
+bench_new 5000
+
+def bench_create(n)
+ puts "-" * 80
+ puts "Trying #{n} iterations"
+
+ fixjour = Benchmark.realtime {
+ n.times { create_article ; create_user }
+ }
+
+ puts "Fixjour 2: #{fixjour}"
+
+ factory_girl = Benchmark.realtime {
+ n.times { Factory(:article) ; Factory(:user) }
+ }
+
+ puts "Factory Girl: #{factory_girl}"
+end
+
+puts "=" * 80
+puts "Benching create records"
+bench_create 100
+bench_create 1000
+bench_create 5000
View
5 bench/Gemfile
@@ -0,0 +1,5 @@
+source :rubygems
+
+gem "fixjour-2"
+gem "factory_girl"
+gem "acts_as_fu"
View
34 bench/Gemfile.lock
@@ -0,0 +1,34 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activemodel (3.2.0)
+ activesupport (= 3.2.0)
+ builder (~> 3.0.0)
+ activerecord (3.2.0)
+ activemodel (= 3.2.0)
+ activesupport (= 3.2.0)
+ arel (~> 3.0.0)
+ tzinfo (~> 0.3.29)
+ activesupport (3.2.0)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ acts_as_fu (0.0.8)
+ activerecord
+ sqlite3
+ arel (3.0.0)
+ builder (3.0.0)
+ factory_girl (2.5.0)
+ activesupport
+ fixjour-2 (0.0.3)
+ i18n (0.6.0)
+ multi_json (1.0.4)
+ sqlite3 (1.3.5)
+ tzinfo (0.3.31)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ acts_as_fu
+ factory_girl
+ fixjour-2

0 comments on commit 8c9009c

Please sign in to comment.
Something went wrong with that request. Please try again.