Do you have a suggestion on how to test performances over two different mongoid/mongodb query implementations?
The implementation to compare, are related to a previous "Q & A" but I'll report those here again, for brevity :
first code :
Competitor = Struct.new(:html_url, :description, :user)
competitors = []
User.all.map do |user|
user.watchlists.all.map do |wl|
if wl.tags_array == ["ruby", "web", "framework"]
competitors << Competitor.new(wl.html_url, wl.description, wl.user.nickname)
end
end
end
vs. second code :
Competitor = Struct.new(:html_url, :description, :user)
competitors = []
User.where('watchlists.tags_array' => %w[ruby web framework]).only(:nickname, :watchlists).each do |u|
u.watchlists.where(:tags_array => %w[ruby web framework]).each do |wl|
competitors << Competitor.new(wl.html_url, wl.description, u.nickname)
end
end
and for completness,
the underline datamodel is :
class User
include Mongoid::Document
field :nickname
embeds_many :watchlists
end
class Watchlist
include Mongoid::Document
field :html_url
field :description
field :tags_array, type: Array
embedded_in :user
end
What's the current way for benchmarking & comparing performances on that two codes ?
Until now, I found this way but if you know something better please answer too ...
first code :
vs. second code :
but even better :
first code :
vs. second code :
then second code results really faster and less cpu consuming ..., thanks to rubish for the "second code"