Sha256: 47d7bb152f9db1b96a24d16bd7424465d8b6c7a005d7eddcbdd6e6bc03521975

Contents?: true

Size: 1.76 KB

Versions: 9

Compression:

Stored size: 1.76 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'benchmark/ips'
require 'socket'

revision = %x(git rev-parse HEAD).rstrip
master_revision = %x(git rev-parse origin/master).rstrip
branch = if revision == master_revision
  'master'
else
  %x(git rev-parse --abbrev-ref HEAD).rstrip
end

intermediate_results_filename = "#{Dir.tmpdir}/statsd-instrument-benchmarks/#{File.basename($PROGRAM_NAME)}"
FileUtils.mkdir_p(File.dirname(intermediate_results_filename))

# Set up an UDP listener to which we can send StatsD packets
receiver = UDPSocket.new
receiver.bind('localhost', 0)

ENV['ENV'] = "production"
ENV['STATSD_ADDR'] = "#{receiver.addr[2]}:#{receiver.addr[1]}"
ENV['STATSD_IMPLEMENTATION'] ||= 'datadog'

require 'statsd-instrument'

report = Benchmark.ips do |bench|
  bench.report("StatsD metrics to local UDP receiver (branch: #{branch}, sha: #{revision[0, 7]})") do
    StatsD.increment('StatsD.increment', 10)
    StatsD.measure('StatsD.measure') { 1 + 1 }
    StatsD.gauge('StatsD.gauge', 12.0, tags: ["foo:bar", "quc"])
    StatsD.set('StatsD.set', 'value', tags: { foo: 'bar', baz: 'quc' })
    if StatsD.backend.implementation == :datadog
      StatsD.event('StasD.event', "12345")
      StatsD.service_check("StatsD.service_check", "ok")
    end
  end

  # Store the results in between runs
  bench.save!(intermediate_results_filename)
  bench.compare!
end

receiver.close

if report.entries.length == 1
  puts
  puts "To compare the performance of this revision against another revision (e.g. master),"
  puts "check out a different branch and run this benchmark script again."
elsif ENV['KEEP_RESULTS']
  puts
  puts "The intermediate results have been stored in #{intermediate_results_filename}"
else
  File.unlink(intermediate_results_filename)
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
statsd-instrument-2.9.2 benchmark/send-metrics-to-local-udp-receiver
statsd-instrument-2.9.1 benchmark/send-metrics-to-local-udp-receiver
statsd-instrument-2.9.0 benchmark/send-metrics-to-local-udp-receiver
statsd-instrument-2.8.0 benchmark/send-metrics-to-local-udp-receiver
statsd-instrument-2.7.1 benchmark/send-metrics-to-local-udp-receiver
statsd-instrument-2.7.0 benchmark/send-metrics-to-local-udp-receiver
statsd-instrument-2.6.0 benchmark/send-metrics-to-local-udp-receiver
statsd-instrument-2.5.1 benchmark/send-metrics-to-local-udp-receiver
statsd-instrument-2.5.0 benchmark/send-metrics-to-local-udp-receiver