I am using datamapper and want to benchmark some queries using ruby benchmark library. To see if it's working I started with a set, comparing methods described in datamapper docs as given below:
(1..1000).each do |i|
i = Item.create :name => "item_#{i}", :weight => 0.5, :volume => 1.2, :price => 15
end
Benchmark.bmbm do |x|
x.report("all:") { Item.all }
x.report("name_only:") { Item.all :fields => [:name] }
x.report("direct_talk_all:") { repository(:default).adapter.select('SELECT * FROM items') }
x.report("direct_talk_name_only:") { repository(:default).adapter.select('SELECT name FROM items') }
end
and surprisingly (to me), the real results were 0, 0.001, 0.024 and 0.014, respectively. It sounds wrong to me that a selective SELECT query costs more time in case I use datamapper-specific code, and that queries take longer when talking directly to the data store.
So, should I go on benchmarking queries this way, or is ruby benchmark library a wrong choice for this?