event_shipper / lib / event_shipper / benchmark.rb

require 'benchmark'
require 'clamp'

module EventShipper
  class Benchmark < Clamp::Command
    def initialize *args
      super

      @s = UDP.new('localhost', 5050)
      @s.wrap Filter::Encrypt.new('user', 'password')

      @r = UDP.new('localhost', 5050)
      @r.wrap Filter::Decrypt.new('user' => 'password')
    end

    def execute
      puts "Simulates 1000 times the sending of a simple message: "
      measure do
        1000.times do _send_message end
      end

      puts "Simulates 1000 times the receiving of a message: "
      msg = _send_message
      measure do
        1000.times do _receive_message(msg) end
      end
    end

    def measure
      puts ::Benchmark.measure {
        yield
      }
    end

    def _send_message
      @s.encode(
        source: 'benchmark', 
        event: 'this is the event')
    end

    def _receive_message msg
      @r.decode(msg)
    end
  end
end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.