I feel evil tonight (here is 3:30am) and then the fortune brought me to the /benchmark directory in ActiveRecord repository (for who doesn’t know what ActiveRecord is, and I think due to the hype everyone knows, see Wikipedia ORM page.).
A while ago someone slapped us with some bench between Rails, Django and Symphony and guess what: Django won hands down. What does it mean winning with raw numbers? To me not much but winning fairly is better than losing cheating. The thing I liked most in that bench page was not the bench itself but a comment at the end:
When connecting rails to Oracle the performance dropped to the extent it made any production use of the product useless.
That sentence is evil because recalls me words like enterprise, enterprisey and whatever that most of the time make me smile.
So, about benchmarks and being evil tonight. ActiveRecord trunk repository has two files in the so-called benchmark sub-directory with two benchs. This:
[code lang="python"] ActiveRecord::Base.establish_connection(:adapter => "mysql", :database => "basecamp")
class Post < ActiveRecord::Base; end
RUNS = ARGV[0].to_i
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}" [/code]
and
[code lang="python"] conn = Mysql::real_connect("localhost", "root", "", "basecamp")
RUNS = ARGV[0].to_i
runtime = Benchmark::measure { RUNS.times { result = conn.query("SELECT * FROM posts LIMIT 100") result.each_hash { |p| p["title"] } } }
puts "Runs: #{RUNS}" puts "Avg. runtime: #{runtime.real / RUNS}" puts "Requests/second: #{RUNS / runtime.real}" [/code]
Let the code and my evilness speak for itself, it’s not time to be sarcastic.




2 Comments
Hi,
I don’t really get your point here and how it relates to the comments above.
I don’t know Ruby but can guess what the above code is doing – maybe it is more my ignorance of Rails or RDBMS’s that is confusing me?
Is it because the 1st one uses ActiveRecord and the 2nd one doesn’t?
Thanks Mark
It’s all about being evil that night and the lame benchmarking cointained in those snippets