Clever but slow: Symbol#to_proc
Ever do something like this in a Rails app and think it was really awesome and convenient?
all_content = Post.find(:all).map(&:content)
Symbol#to_proc is really neat but is expensive as heck.
Here’s some sample benchmarks:
user system total real
without to_proc 0.840000 0.000000 0.840000 ( 0.858780)
with to_proc 1.780000 0.020000 1.800000 ( 1.816275)
That means code that looks like this:
(1..100).inject(&:+)
looks really neat but is quite a bit slower than
(1..100).inject {|sum, n| sum + n }
ActiveRecord, your Ruby-Fu may be strong but it’s going to cramp my style.