aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/commands/performance/benchmarker.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-09-30 22:27:02 +0100
committerPratik Naik <pratiknaik@gmail.com>2009-09-30 22:27:02 +0100
commitdd2779e1b83b4d867d47dd286ec0c919f5df12a9 (patch)
tree6e52ea0a329c24429f4d1d41b065e082f0ed6baa /railties/lib/rails/commands/performance/benchmarker.rb
parent329b14aa8fdd291a00d17ba12c2e0ab4c3a157cc (diff)
parent420004e030e96f2ace6e27fd622c90ee9e986677 (diff)
downloadrails-dd2779e1b83b4d867d47dd286ec0c919f5df12a9.tar.gz
rails-dd2779e1b83b4d867d47dd286ec0c919f5df12a9.tar.bz2
rails-dd2779e1b83b4d867d47dd286ec0c919f5df12a9.zip
Merge commit 'mainstream/master'
Diffstat (limited to 'railties/lib/rails/commands/performance/benchmarker.rb')
-rw-r--r--railties/lib/rails/commands/performance/benchmarker.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/railties/lib/rails/commands/performance/benchmarker.rb b/railties/lib/rails/commands/performance/benchmarker.rb
new file mode 100644
index 0000000000..e8804fe1bf
--- /dev/null
+++ b/railties/lib/rails/commands/performance/benchmarker.rb
@@ -0,0 +1,24 @@
+if ARGV.empty?
+ puts "Usage: ./script/performance/benchmarker [times] 'Person.expensive_way' 'Person.another_expensive_way' ..."
+ exit 1
+end
+
+begin
+ N = Integer(ARGV.first)
+ ARGV.shift
+rescue ArgumentError
+ N = 1
+end
+
+require RAILS_ROOT + '/config/environment'
+require 'benchmark'
+include Benchmark
+
+# Don't include compilation in the benchmark
+ARGV.each { |expression| eval(expression) }
+
+bm(6) do |x|
+ ARGV.each_with_index do |expression, idx|
+ x.report("##{idx + 1}") { N.times { eval(expression) } }
+ end
+end