readability vs. speed

| | Comments (2)

Which one is better? You decide...

if true then # 0.75 seconds
  require 'active_record'
  require 'yaml'
  require 'app/models/author'
  require 'app/models/project'
  config = YAML.load(File.read('config/database.yml'))
  ActiveRecord::Base.establish_connection(config["development"])
else # 2.0 seconds
  require File.dirname(__FILE__) + '/../config/environment'
end

conn = ActiveRecord::Base.connection

I'm slightly partial to the faster running one (esp. during development)... but it did take me a while to figger it out. Loading config/environment a heavy price to pay just to get a DB connection and automatic requires.

2 Comments

I prefer looking at the 2nd one... but 2 seconds is a mighty long time.

Is that true even with devmodeperformance_fixes?

Leave a comment

About this Entry

This page contains a single entry by zenspider published on September 17, 2007 9:04 PM.

vlad version 1.1.0 has been released! was the previous entry in this blog.

ParseTree version 2.0.2 has been released! is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Pages

Powered by Movable Type 4.32-en