I have a pretty expensive method in my model that compares text items of arrays for many many items.
It runs really slow. If I use a relational database table and compare the ID’s only, will my method run a lot faster?
/EDIT
I’m attempting to benchmark the below:
@matches = @location_matches.sort do |l1, l2|
l1.compute_score(current_user) <=> l2.compute_score(current_user)
end
@matches.reverse!
To be short, I guess number comparison will be faster because comparing string is about comparing character after character (advice: in Ruby use symbols when you can, their comparison is much faster).
Whatever, you’ll find there, everything you need to benchmark and get your detailled results.
A code sample:
The result: