aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/benchmarks/benchmark.rb
blob: 241d91520876c41b9fa4e52d313627eff35ed3b0 (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'
  require_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}"