aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/commands/perform/benchmarker.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/commands/perform/benchmarker.rb')
-rw-r--r--railties/lib/commands/perform/benchmarker.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/railties/lib/commands/perform/benchmarker.rb b/railties/lib/commands/perform/benchmarker.rb
new file mode 100644
index 0000000000..b07ddcfcb2
--- /dev/null
+++ b/railties/lib/commands/perform/benchmarker.rb
@@ -0,0 +1,19 @@
+#!/usr/local/bin/ruby
+
+if ARGV.empty?
+ puts "Usage: benchmarker times 'Person.expensive_way' 'Person.another_expensive_way' ..."
+ exit
+end
+
+require File.dirname(__FILE__) + '/../config/environment'
+require 'benchmark'
+include Benchmark
+
+# Don't include compilation in the benchmark
+ARGV[1..-1].each { |expression| eval(expression) }
+
+bm(6) do |x|
+ ARGV[1..-1].each_with_index do |expression, idx|
+ x.report("##{idx + 1}") { ARGV[0].to_i.times { eval(expression) } }
+ end
+end \ No newline at end of file