Class: EventShipper::Benchmark

Inherits:
Clamp::Command
  • Object
show all
Defined in:
lib/event_shipper/benchmark.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Benchmark

Returns a new instance of Benchmark.



7
8
9
10
11
12
13
14
15
# File 'lib/event_shipper/benchmark.rb', line 7

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

Instance Method Details

#_receive_message(msg) ⇒ Object



42
43
44
# File 'lib/event_shipper/benchmark.rb', line 42

def _receive_message msg
  @r.decode(msg)
end

#_send_messageObject



36
37
38
39
40
# File 'lib/event_shipper/benchmark.rb', line 36

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

#executeObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/event_shipper/benchmark.rb', line 17

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

#measureObject



30
31
32
33
34
# File 'lib/event_shipper/benchmark.rb', line 30

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