Jian Lin wrote:
> i changed it to
> 
>   time_start = Time.now
>   Phrase.transaction do
>     all_phrases.each do |phrase|
>     recordPhrase = Phrase.create!(:s => phrase, :frequency => 
> frequencies[phrase], :length => lengths[phrase])
>     end
>   end
>   p "took ", Time.now - time_start, " seconds to finish"
> 
> but it is still the same: it took 75 seconds...

That's because it's still really the same code!

> i wanted the length, which is the count of word because in the future i 
> might want to do query such as  "select * where length > 3" and so if i 
> count the word by getting "s" first, then it will be really slow won't 
> it?  if length is stored and indexed, then "length > 3" can be super 
> fast?

Just because it has an index on it doesn't automatically make it super 
fast. It depends largely on the selectivity of the length field. I 
suspect that most of your phrases are larger than 3 characters and so 
such a query will result in a full table scan anyway. In that case 
making the table smaller by leaving out the length may actually make it 
faster. However, selecting all the phrases where length < 5 would almost 
certainly use the index and make it faster. Only you know what you are 
likely to do in general here so you need to decide (and test) whether it 
is better to have the index and length column or not.

You can always do "select * from phrases where length(s) > 3" or 
something like.

Are you sure your overall run time is not limited by CPU rather than IO? 
How much CPU time is used to run your code?

Cheers,
Gary.



--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to