I am trying to get all identifiers from my article model. I can do this in two ways:
Article.select(:id).collect{|a| a.id}
Article Load (2.6ms) SELECT "articles"."id" FROM "articles"
OR
2.2.1 :006 > Article.pluck(:id)
(4.3ms) SELECT "articles"."id" FROM "articles"
What gives? Why is AR slower than the Ruby version?
Even when I compare the Ruby method, it looks faster:
Benchmark.measure{Article.select(:id).collect{|a| a.id}}
Article Load (1.9ms) SELECT "articles"."id" FROM "articles"
=> #<Benchmark::Tms:0x007feb12060658 @label="", @real=0.026455502957105637, @cstime=0.0, @cutime=0.0, @stime=0.0, @utime=0.020000000000000018, @total=0.020000000000000018>
source
share