rails/rails — pull request #15313 by andreychernih (2014-05-25 09:02:29+00:00)
Title: Speed-up TimeWithZone to String conversion

I've noticed that `String(model.created_at)` is performing poorly in comparision
with other fields. The source of the problem is a way `Kernel#String` works: it first
tries to call `to_str` (which causes `NoMethodError` in `method_missing`) and then calls `to_s`.

Performance tests:

tz = Time.zone.now

Without this code:

puts Benchmark.measure { 100_000.times { String(tz) } } # => 10.120000 0.050000 10.170000 ( 10.160466)

With this code:

puts Benchmark.measure { 100_000.times { String(tz) } } # => 0.780000 0.080000 0.860000 ( 0.856519)