Skip to content

Instantly share code, notes, and snippets.

@Erol
Last active December 18, 2015 22:49
Show Gist options
  • Save Erol/5856852 to your computer and use it in GitHub Desktop.
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
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
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