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

Version Path
activerecord-turntable-2.5.0 script/performance/algorithm
activerecord-turntable-2.4.0 script/performance/algorithm
activerecord-turntable-2.3.3 script/performance/algorithm
activerecord-turntable-2.3.2 script/performance/algorithm
activerecord-turntable-2.3.1 script/performance/algorithm
activerecord-turntable-2.3.0 script/performance/algorithm
activerecord-turntable-2.2.2 script/performance/algorithm
activerecord-turntable-2.2.1 script/performance/algorithm
activerecord-turntable-2.2.0 script/performance/algorithm
activerecord-turntable-2.1.1 script/performance/algorithm
activerecord-turntable-2.1.0 script/performance/algorithm
activerecord-turntable-2.1.0.rc2 script/performance/algorithm
activerecord-turntable-2.1.0.rc1 script/performance/algorithm
activerecord-turntable-2.1.0.beta2 script/performance/algorithm
activerecord-turntable-2.1.0.beta1 script/performance/algorithm
activerecord-turntable-2.0.6 script/performance/algorithm
activerecord-turntable-2.0.5 script/performance/algorithm
activerecord-turntable-2.0.4 script/performance/algorithm
activerecord-turntable-2.0.3 script/performance/algorithm
activerecord-turntable-2.0.2 script/performance/algorithm