Sha256: 7a32261fc380999fc464c8645bd55ef499fd520369ae8195f8f00757d217a2fd
Contents?: true
Size: 821 Bytes
Versions: 28
Compression:
Stored size: 821 Bytes
Contents
#!/usr/bin/env ruby require 'rspec' require File.join(File.dirname(__FILE__), '../../../spec/spec_helper') require 'benchmark' def setup_algorithm(n, alg = "Range") config = { "shards" => n.times.map do |i| {"connection" => "connection_#{i}", "less_than" => (i+1) * 100} end } "ActiveRecord::Turntable::Algorithm::#{alg}Algorithm".constantize.new(config) end Benchmark.bm(40) do |x| %w(Range RangeBsearch).each do |alg| [2, 4, 8, 16, 32, 64, 128, 256, 512].map do |n| algorithm = setup_algorithm(n, alg) x.report("#{alg}: selrand(#{n}) * 1000") { 1000.times do algorithm.calculate(rand(n*100)) end } x.report("#{alg}: sellast(#{n}) * 1000") { 1000.times do algorithm.calculate(n*100-1) end } end end end
Version data entries
28 entries across 28 versions & 1 rubygems