Last active
December 18, 2015 22:49
-
-
Save Erol/5856852 to your computer and use it in GitHub Desktop.
Benchmark: Select from an Ohm Model's All Set vs Arrays Directly Returned by Redis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
User.all.size #=> 30000 | |
Benchmark.bm(30) do |bm| | |
bm.report 'User Instances' do | |
User.all | |
.select { |user| user.lastname.downcase == 'erol' } | |
end | |
bm.report 'Redis-Returned Arrays' do | |
ids = User.all.key.sort(by: '#', get: ['#', 'User:*->firstname']) | |
.select { |values| values[1].downcase == 'erol' } | |
.map { |values| values[0] } | |
User.all.fetch ids | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user system total real | |
Ohm Model Instances 56.700000 1.350000 58.050000 ( 58.561028) | |
Redis-Returned Arrays 1.840000 0.020000 1.860000 ( 2.171307) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment