Sha256: 7adaeb37880524873bc1400efaa22112ff14c92e9874db2413ef77ca364804fa

Contents?: true

Size: 767 Bytes

Versions: 38

Compression:

Stored size: 767 Bytes

Contents

require 'bundler/setup'
require 'flipper'

stats = Flipper[:stats]

# Some class that represents what will be trying to do something
class User < Struct.new(:id)
  include Flipper::Identifier
end

total = 100_000

# create array of fake users
users = (1..total).map { |n| User.new(n) }

perform_test = lambda { |number|
  Flipper.enable_percentage_of_actors :stats, number

  enabled = users.map { |user|
    Flipper.enabled?(:stats, user) ? true : nil
  }.compact

  actual = (enabled.size / total.to_f * 100).round(3)

  puts "percentage: #{actual.to_s.rjust(6, ' ')} vs #{number.to_s.rjust(3, ' ')}"
}

puts "percentage: Actual vs Hoped For"
[0.001, 0.01, 0.1, 1, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 95, 99, 100].each do |number|
  perform_test.call number
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
flipper-1.3.2 examples/percentage_of_actors.rb
flipper-1.3.1 examples/percentage_of_actors.rb
flipper-1.3.0 examples/percentage_of_actors.rb
flipper-1.3.0.pre examples/percentage_of_actors.rb
flipper-1.2.2 examples/percentage_of_actors.rb
flipper-1.2.1 examples/percentage_of_actors.rb
flipper-1.2.0 examples/percentage_of_actors.rb
flipper-1.1.2 examples/percentage_of_actors.rb
flipper-1.1.1 examples/percentage_of_actors.rb
flipper-1.1.0 examples/percentage_of_actors.rb
flipper-1.0.0 examples/percentage_of_actors.rb
flipper-1.0.0.pre examples/percentage_of_actors.rb
flipper-0.28.3 examples/percentage_of_actors.rb
flipper-0.28.2 examples/percentage_of_actors.rb
flipper-0.28.1 examples/percentage_of_actors.rb
flipper-0.28.0 examples/percentage_of_actors.rb
flipper-0.27.1 examples/percentage_of_actors.rb
flipper-0.27.0 examples/percentage_of_actors.rb
flipper-0.26.2 examples/percentage_of_actors.rb
flipper-0.26.1 examples/percentage_of_actors.rb