Pål Bergström
2009-Feb-21 19:13 UTC
How fast is Model.average compared to a find all and loop?
I have a set of results that I want to find some average values, divided into group_1, _2, and _3. I have two options. 1) Find all and then loop through all and in each loop calculate how many there are and the summery for each and get the average for each. 2) Use the calculation method Model.average() 3 times. Which one is fastest? And what happens when there are more groups? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Craig Demyanovich
2009-Feb-21 20:42 UTC
Re: How fast is Model.average compared to a find all and loop?
You should try both and report back. :-) Regards, Craig --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Pål Bergström
2009-Feb-21 20:57 UTC
Re: How fast is Model.average compared to a find all and lo
Craig Demyanovich wrote:> You should try both and report back. :-) > > Regards, > CraigI don''t have so many post in my db and I thought someone might have the answer. I''ll will add some and try it. :-) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Feb-21 23:14 UTC
Re: How fast is Model.average compared to a find all and lo
On Feb 21, 8:57 pm, Pål Bergström <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Craig Demyanovich wrote: > > You should try both and report back. :-) > > > Regards, > > Craig > > I don''t have so many post in my db and I thought someone might have the > answer. I''ll will add some and try it. :-)I would expect Model.average to be much faster - aggregating lots of data is something databases are good at, and something for which instantiating 10s of thousands of active record objects is unnecessary. Fred> -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Pål Bergström
2009-Feb-22 06:55 UTC
Re: How fast is Model.average compared to a find all and lo
Frederick Cheung wrote:> On Feb 21, 8:57�pm, P�l Bergstr�m <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote:> I would expect Model.average to be much faster - aggregating lots of > data is something databases are good at, and something for which > instantiating 10s of thousands of active record objects is > unnecessary. > > FredThanks. That was what I suspected. :) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---