Created
February 19, 2016 02:42
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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