Kaspar Schiess avatar Kaspar Schiess committed b65ce43

And a receiving end benchmark

Comments (0)

Files changed (2)

lib/event_shipper/benchmark.rb

     def initialize *args
       super
 
-      @udp = UDP.new('localhost', 5050)
-      @udp.wrap Filter::Encrypt.new('user', 'password')
+      @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: "
-      puts ::Benchmark.measure {
+      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
-      @udp.encode(
+      @s.encode(
         source: 'benchmark', 
         event: 'this is the event')
     end
+
+    def _receive_message msg
+      @r.decode(msg)
+    end
   end
 end

lib/event_shipper/protocol.rb

 
   def parse_encrypted string
     Encrypted.new.tap { |o|
-      o.parse_from_string(string) }
+      o.parse(string) }
   end
   def parse_transmission string
     Transmission.new.tap { |o| 
-      o.parse_from_string(string) }
+      o.parse(string) }
   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.