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

Version Path
logstash-output-scalyr-0.2.7.beta spec/benchmarks/metrics_overhead.rb
logstash-output-scalyr-0.2.6 spec/benchmarks/metrics_overhead.rb
logstash-output-scalyr-0.2.6.beta spec/benchmarks/metrics_overhead.rb
logstash-output-scalyr-0.2.5.beta spec/benchmarks/metrics_overhead.rb
logstash-output-scalyr-0.2.4.beta spec/benchmarks/metrics_overhead.rb
logstash-output-scalyr-0.2.3 spec/benchmarks/metrics_overhead.rb
logstash-output-scalyr-0.2.2 spec/benchmarks/metrics_overhead.rb
logstash-output-scalyr-0.2.1.beta spec/benchmarks/metrics_overhead.rb
logstash-output-scalyr-0.2.0 spec/benchmarks/metrics_overhead.rb
logstash-output-scalyr-0.2.0.beta spec/benchmarks/metrics_overhead.rb
logstash-output-scalyr-0.1.26.beta spec/benchmarks/metrics_overhead.rb
logstash-output-scalyr-0.1.25.beta spec/benchmarks/metrics_overhead.rb
logstash-output-scalyr-0.1.24.beta spec/benchmarks/metrics_overhead.rb
logstash-output-scalyr-0.1.23.beta spec/benchmarks/metrics_overhead.rb
logstash-output-scalyr-0.1.22.beta spec/benchmarks/metrics_overhead.rb
logstash-output-scalyr-0.1.21.beta spec/benchmarks/metrics_overhead.rb
logstash-output-scalyr-0.1.20.beta spec/benchmarks/metrics_overhead.rb
logstash-output-scalyr-0.1.19.beta spec/benchmarks/metrics_overhead.rb
logstash-output-scalyr-0.1.18.beta spec/benchmarks/metrics_overhead.rb
logstash-output-scalyr-0.1.17.beta spec/benchmarks/metrics_overhead.rb