Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aquajach/f875e13773ace44d6f85 to your computer and use it in GitHub Desktop.
Save aquajach/f875e13773ace44d6f85 to your computer and use it in GitHub Desktop.
read_attribute_before_type_cast is 50% faster than read_attribute when type casting is required
require 'benchmark'
person = Person.new(created_at: '2016-2-19')
time_1 = Benchmark.realtime do
100000.times do
person.read_attribute_before_type_cast(:created_at)
end
end
time_2 = Benchmark.realtime do
100000.times do
person.read_attribute(:created_at)
end
end
p time_1 #0.053
p time_2 #0.079
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment