Sha256: 13c68b9698f9f365da9b845ade13dcc4188d7f0f78f000e08fd41a44db14b706

Contents?: true

Size: 1.41 KB

Versions: 22

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

require 'bundler/setup'
require 'polyphony'
require 'tipi/digital_fabric'

class FakeAgent
  def initialize(idx)
    @idx = idx
  end
end

def setup_df_service_with_agents(agent_count)
  server = DigitalFabric::Service.new
  agent_count.times do |i|
    server.mount({path: "/#{i}"}, FakeAgent.new(i))
  end
  server
end

def benchmark_route_compilation(agent_count, iterations)
  service = setup_df_service_with_agents(agent_count)
  t0 = Time.now
  iterations.times { service.compile_agent_routes }
  elapsed = Time.now - t0
  puts "route_compilation: #{agent_count} => #{elapsed / iterations}s (#{1/(elapsed / iterations)} ops/sec)"
end

class FauxRequest
  def initialize(agent_count)
    @agent_count = agent_count
  end

  def headers
    { ':path' => "/#{rand(@agent_count)}"}
  end
end

def benchmark_find_agent(agent_count, iterations)
  service = setup_df_service_with_agents(agent_count)
  t0 = Time.now
  request = FauxRequest.new(agent_count)
  iterations.times do
    agent = service.find_agent(request)
  end
  elapsed = Time.now - t0
  puts "routing: #{agent_count} => #{elapsed / iterations}s (#{1/(elapsed / iterations)} ops/sec)"
end

def benchmark
  benchmark_route_compilation(100, 1000)
  benchmark_route_compilation(500,  200)
  benchmark_route_compilation(1000, 100)

  benchmark_find_agent(100, 1000)
  benchmark_find_agent(500,  200)
  benchmark_find_agent(1000, 100)
end

benchmark

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
tipi-0.55 df/routing_benchmark.rb
tipi-0.54 df/routing_benchmark.rb
tipi-0.53 df/routing_benchmark.rb
tipi-0.52 df/routing_benchmark.rb
tipi-0.51 df/routing_benchmark.rb
tipi-0.50 df/routing_benchmark.rb
tipi-0.49 df/routing_benchmark.rb
tipi-0.47 df/routing_benchmark.rb
tipi-0.46 df/routing_benchmark.rb
tipi-0.45 df/routing_benchmark.rb
tipi-0.43 df/routing_benchmark.rb
tipi-0.42 df/routing_benchmark.rb
tipi-0.41 df/routing_benchmark.rb
tipi-0.40 df/routing_benchmark.rb
tipi-0.39 df/routing_benchmark.rb
tipi-0.38 df/routing_benchmark.rb
tipi-0.37.2 df/routing_benchmark.rb
tipi-0.37.1 df/routing_benchmark.rb
tipi-0.37 df/routing_benchmark.rb
tipi-0.36 df/routing_benchmark.rb