Skip to content

Instantly share code, notes, and snippets.

@sixfeetover
Last active December 16, 2015 10:58
Show Gist options
  • Save sixfeetover/5423568 to your computer and use it in GitHub Desktop.
Save sixfeetover/5423568 to your computer and use it in GitHub Desktop.
require 'redis'
require 'hiredis'
require "redis/connection/hiredis"
total = 0
conn = Redis.new(db: 1, driver: :hiredis, path: '/tmp/redis.sock')
(1000...1100).each do |section|
key = "section:#{section}"
values = []
(0...10).each do |i|
(0...5).each do |j|
(0...10).each do |k|
(0...80).each do |l|
values << [i, j, k, l].join(':')
end
end
end
total += conn.sadd(key, values)
end
end
puts "Total: #{total}"
# ruby 2.0
# no GC tuning: ruby r.rb 16.12s user 0.67s system 55% cpu 30.312 total
# GC tuning: RUBY_GC_MALLOC_LIMIT=90000000 ruby r.rb 15.41s user 0.63s system 59% cpu 27.132 total
require 'redis'
require 'hiredis'
require "redis/connection/hiredis"
total = 0
conn = Redis.new(db: 1, driver: :hiredis, path: '/tmp/redis.sock')
(1000...1100).each do |section|
key = "section:#{section}"
values = Array.new(10 * 5 * 10 * 80)
(0...10).each do |i|
(0...5).each do |j|
(0...10).each do |k|
(0...80).each do |l|
values << [i, j, k, l].join(':')
end
end
end
total += conn.sadd(key, values)
end
end
puts "Total: #{total}"
# Ruby 2.0
# no GC tuning: ruby r.rb 32.29s user 1.21s system 51% cpu 1:05.55 total
# GC tuning: RUBY_GC_MALLOC_LIMIT=90000000 ruby r.rb 32.20s user 1.29s system 51% cpu 1:04.51 total
#require 'redis'
require 'hiredis'
#require "redis/connection/hiredis"
total = 0
#conn = Redis.new(db: 1, driver: :hiredis, path: '/tmp/redis.sock')
conn = Hiredis::Connection.new
conn.connect("127.0.0.1", 6379)
conn.write ["select", 1]
conn.read
(1000...1100).each do |section|
key = "section:#{section}"
values = []#Array.new(10 * 5 * 10 * 80)
(0...10).each do |i|
(0...5).each do |j|
(0...10).each do |k|
(0...80).each do |l|
values << [i, j, k, l].join(':')
end
end
end
#total += conn.sadd(key, values)
conn.write ["sadd", key, values]
total += conn.read
end
end
puts "Total: #{total}"
# No GC: ruby r.rb 13.72s user 0.34s system 52% cpu 26.928 total
# No GC, array preallocated: ruby hiredis_version.rb 27.18s user 0.54s system 46% cpu 1:00.11 total
# GC: RUBY_GC_MALLOC_LIMIT=90000000 ruby r.rb 13.72s user 0.33s system 51% cpu 27.079 total
# GC, array preallocated: RUBY_GC_MALLOC_LIMIT=90000000 ruby hiredis_version.rb 27.03s user 0.56s system 46% cpu 59.928 total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment