aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/examples
diff options
context:
space:
mode:
authorGonçalo Silva <goncalossilva@gmail.com>2011-05-08 03:54:55 +0100
committerGonçalo Silva <goncalossilva@gmail.com>2011-05-08 03:54:55 +0100
commitaec7456f81985b88d6d604679d754636183b5b3a (patch)
tree798fcab8ae0c6e2c8c5a63e1f39308ff4bb5a20c /activeresource/examples
parent1c2b2233c3a7ec76c0a0eddf5b8be45c489be133 (diff)
parent70f9558d0e4b8e605576693cbb489caa5cf6a2bc (diff)
downloadrails-aec7456f81985b88d6d604679d754636183b5b3a.tar.gz
rails-aec7456f81985b88d6d604679d754636183b5b3a.tar.bz2
rails-aec7456f81985b88d6d604679d754636183b5b3a.zip
Merge branch 'master' of https://github.com/rails/rails into performance_test
Conflicts: activesupport/lib/active_support/testing/performance.rb
Diffstat (limited to 'activeresource/examples')
-rw-r--r--activeresource/examples/performance.rb70
1 files changed, 70 insertions, 0 deletions
diff --git a/activeresource/examples/performance.rb b/activeresource/examples/performance.rb
new file mode 100644
index 0000000000..e4df7a38a4
--- /dev/null
+++ b/activeresource/examples/performance.rb
@@ -0,0 +1,70 @@
+require 'rubygems'
+require 'active_resource'
+require 'benchmark'
+
+TIMES = (ENV['N'] || 10_000).to_i
+
+# deep nested resource
+attrs = {
+ :id => 1,
+ :name => 'Luis',
+ :age => 21,
+ :friends => [
+ {
+ :name => 'JK',
+ :age => 24,
+ :colors => ['red', 'green', 'blue'],
+ :brothers => [
+ {
+ :name => 'Mateo',
+ :age => 35,
+ :children => [{ :name => 'Edith', :age => 5 }, { :name => 'Martha', :age => 4 }]
+ },
+ {
+ :name => 'Felipe',
+ :age => 33,
+ :children => [{ :name => 'Bryan', :age => 1 }, { :name => 'Luke', :age => 0 }]
+ }
+ ]
+ },
+ {
+ :name => 'Eduardo',
+ :age => 20,
+ :colors => [],
+ :brothers => [
+ {
+ :name => 'Sebas',
+ :age => 23,
+ :children => [{ :name => 'Andres', :age => 0 }, { :name => 'Jorge', :age => 2 }]
+ },
+ {
+ :name => 'Elsa',
+ :age => 19,
+ :children => [{ :name => 'Natacha', :age => 1 }]
+ },
+ {
+ :name => 'Milena',
+ :age => 16,
+ :children => []
+ }
+ ]
+ }
+ ]
+}
+
+class Customer < ActiveResource::Base
+ self.site = "http://37s.sunrise.i:3000"
+end
+
+module Nested
+ class Customer < ActiveResource::Base
+ self.site = "http://37s.sunrise.i:3000"
+ end
+end
+
+Benchmark.bm(40) do |x|
+ x.report('Model.new (instantiation)') { TIMES.times { Customer.new } }
+ x.report('Nested::Model.new (instantiation)') { TIMES.times { Nested::Customer.new } }
+ x.report('Model.new (setting attributes)') { TIMES.times { Customer.new attrs } }
+ x.report('Nested::Model.new (setting attributes)') { TIMES.times { Nested::Customer.new attrs } }
+end