aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorAndrey Chernih <andrey.chernih@gmail.com>2014-05-25 12:55:29 +0400
committerAndrey Chernih <andrey.chernih@gmail.com>2014-05-27 17:38:34 +0400
commit3a0888203031b91a583f8ce35763f8d231467827 (patch)
tree22bfcabd391b00d95d03a9be6b327b02d7b0f351 /guides
parentf632f79b8dcd144408c66a544984b2ba9cf52f87 (diff)
downloadrails-3a0888203031b91a583f8ce35763f8d231467827.tar.gz
rails-3a0888203031b91a583f8ce35763f8d231467827.tar.bz2
rails-3a0888203031b91a583f8ce35763f8d231467827.zip
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 Benchmark.ips do |x| x.report { String(tz) } end Without this code: Calculating ------------------------------------- 572 i/100ms ------------------------------------------------- 10177.7 (±18.2%) i/s - 48620 in 5.000325s With this code: Calculating ------------------------------------- 1518 i/100ms ------------------------------------------------- 138984.2 (±10.1%) i/s - 677028 in 4.974897s
Diffstat (limited to 'guides')
0 files changed, 0 insertions, 0 deletions