Sha256: 3134515a82cff5cf36bf270a3c37a58ded7b7a2f9440acabd767e53c92f76b92
Contents?: true
Size: 844 Bytes
Versions: 12
Compression:
Stored size: 844 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, }.with_indifferent_access "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
12 entries across 12 versions & 1 rubygems