Sha256: 7a920044289ade51981702baa20128bc96e00a9ce0696c3ce1f4d4149f411495

Contents?: true

Size: 1.13 KB

Versions: 6

Compression:

Stored size: 1.13 KB

Contents

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

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

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

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

require 'statsd-instrument'

legacy_client = StatsD

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

udp_sink = StatsD::Instrument::UDPSink.new(new_client_receiver.addr[2], new_client_receiver.addr[1])
new_client = StatsD::Instrument::Client.new(sink: udp_sink, default_sample_rate: StatsD.default_sample_rate)

Benchmark.ips do |bench|
  bench.report("Legacy client (sample rate: #{StatsD.default_sample_rate})") do
    legacy_client.increment('StatsD.increment')
  end

  bench.report("New client (sample rate: #{StatsD.default_sample_rate})") do
    new_client.increment('StatsD.increment')
  end

  bench.compare!
end

legacy_receiver.close
new_client_receiver.close

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
statsd-instrument-2.9.2 benchmark/datagram-client
statsd-instrument-2.9.1 benchmark/datagram-client
statsd-instrument-2.9.0 benchmark/datagram-client
statsd-instrument-2.8.0 benchmark/datagram-client
statsd-instrument-2.7.1 benchmark/datagram-client
statsd-instrument-2.7.0 benchmark/datagram-client