aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/benchmarks/benchmark.rb
blob: de390c11b2a36b7d3cd8d862c31445cd0351805a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$:.unshift(File.dirname(__FILE__) + '/../lib')
if ARGV[2]
  require 'rubygems'
  gem 'activerecord', ARGV[2]
else
  require 'active_record'
end

ActiveRecord::Base.establish_connection(:adapter => "mysql", :database => "basecamp")

class Post < ActiveRecord::Base; end

require 'benchmark'

RUNS = ARGV[0].to_i
if ARGV[1] == "profile" then require 'profile' end

runtime = Benchmark::measure {
  RUNS.times { 
    Post.find_all(nil,nil,100).each { |p| p.title }
  }
}

puts "Runs: #{RUNS}"
puts "Avg. runtime: #{runtime.real / RUNS}"
puts "Requests/second: #{RUNS / runtime.real}"