Skip to content


dhoss edited this page Nov 6, 2014 · 12 revisions

This is a list of benchmarks done as experiments to determine whether or not to change certain pieces of code.

tree_for: using WHERE IN(...) vs Model.find_by_sql(query)

Parameters: Retrieve root nodes with 50 descendants 1000 times.


Query WHERE IN (...) Model.find_by_sql(query)
Execution time (real) 0.010050 0.015138

I've run this several times and WHERE IN (...) is faster each time. However, it doesn't create the row objects like find_by_sql does, and it only retrieves the ID of each row, which essentially causes another trip to the database when you go to use the data. I'm not very concerned as I'd rather have functionality that can be optimized later instead of what I have now, which causes a lot of hackiness in order to retrieve other columns in other places in the code.

Clone this wiki locally
You can’t perform that action at this time.