From: Todd Benson Date: 2008-08-26T04:32:28+09:00 Subject: Re: Which is faster for repetition: Ruby or SQL? On Mon, Aug 25, 2008 at 1:44 PM, Jason Crystal wrote: > Hey all, > > I was wondering if there was a general consensus for whether it's faster > to do repetitive queries solely through Ruby (as on an array), or to > make multiple calls to a SQL database of some sort. > > For example, if I have a dictionary, and I know I need to compare an > entire paragraph's worth of words to the dictionary, should I query each > word against the database? Or load the entire dictionary into a Ruby > object and index against that? > > Thanks for your thoughts! > -Jason Depends on your database, how you connect to it (net/local), and the size/volatility of your paragraph/dictionary. I'd say, split the words out of the string and build a single SQL query in Ruby (probably the brunt of it will go in the 'where' clause). I would wager it would be almost infinitely faster than your proposed options. With my idea, the bottleneck probably would lie at the connection. Something to think about, anyway. Todd