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