Sha256: f3758c21c69a5d03eea1e7e907a3a19baf8b76f8cddd1918308f16fa4ea3db1b
Contents?: true
Size: 1.04 KB
Versions: 29
Compression:
Stored size: 1.04 KB
Contents
require 'benchmark' require 'quantile' require_relative '../../lib/scalyr/common/util' # Micro benchmark which measures how much overhead Quantile.observe adds vs random sampling to see # where making sampling (e.g. on event level metrics) is desired ITERATIONS = 10000 def run_benchmark_and_print_results(run_benchmark_func) result = [] ITERATIONS.times do |i| result << Benchmark.measure { run_benchmark_func.() } end sum = result.inject(nil) { |sum, t| sum.nil? ? sum = t : sum += t } avg = sum / result.size Benchmark.bm(7, "sum:", "avg:") do |b| [sum, avg] end puts "" end puts "Using %s iterations" % [ITERATIONS] puts "" @value = Quantile::Estimator.new @prng = Random.new def quantile_observe() @value.observe(5) end def random_sample() return @prng.rand(0.0..1.0) < 0.5 end puts "Quartile.observe()" puts "===============================" run_benchmark_and_print_results(method(:quantile_observe)) puts "random sample" puts "===============================" run_benchmark_and_print_results(method(:random_sample))
Version data entries
29 entries across 29 versions & 1 rubygems