diff --git a/tests/performances/ipc_connection.cr b/tests/performances/ipc_connection.cr index 0056a1e..07d2c1e 100644 --- a/tests/performances/ipc_connection.cr +++ b/tests/performances/ipc_connection.cr @@ -5,19 +5,13 @@ require "../test-ws" ws_uri = "ws://localhost:1234/pong.JSON" message = IPC::Message.from_json(%({ "mtype" : 3, "utype" : 30, "payload" : "coucou" })) -pong = IPC::Connection.new "pong" Benchmark.ips do |bm| bm.report("connection") do - c = IPC::Connection.new "pong" + c = IPC::Client.new "pong" + end + + bm.report("connection through websocket") do + tws = TestWS.new ws_uri end end - -#puts "sleeping 5 seconds" -#sleep 5 -# -#Benchmark.ips do |bm| -# bm.report("connection through websocket") do -# tws = TestWS.new ws_uri -# end -#end diff --git a/tests/performances/ipc_message_exchange.cr b/tests/performances/ipc_message_exchange.cr index 6e1f588..9d2cbb9 100644 --- a/tests/performances/ipc_message_exchange.cr +++ b/tests/performances/ipc_message_exchange.cr @@ -2,25 +2,44 @@ require "benchmark" require "ipc" require "../test-ws" -ws_uri = "ws://localhost:1234/pong" +ws_uri = "ws://localhost:1234/pong" ws_uri_json = "ws://localhost:1234/pong.JSON" + ws_pong = TestWS.new ws_uri ws_pong_json = TestWS.new ws_uri_json -pong = IPC::Connection.new "pong" +pong = IPC::Client.new "pong" +pong.base_timer = 100_000 +pong.timer = 100_000 Benchmark.ips do |bm| bm.report("direct: round trip time") do - pong.send 42, "coucou" - m = pong.read + # puts "direct: round trip time" + pong.send pong.server_fd.not_nil!, 42, "coucou" + ::loop do + event = pong.wait_event do |event| + end + + case event + when IPC::Event::MessageSent + # OK + when IPC::Event::MessageReceived + # puts "message received" + break + else + puts "event: #{event}" + end + end end - bm.report("web sockets: round trip time") do - ws_pong.send 42, "coucou" - m = ws_pong.read - end + #bm.report("web sockets: round trip time") do + # # puts "web sockets: round trip time" + # ws_pong.send 42, "coucou" + # m = ws_pong.read + #end bm.report("web sockets + json: round trip time") do + # puts "web sockets + json: round trip time" ws_pong_json.send 42, "coucou" m = ws_pong_json.read end diff --git a/tests/test-ws.cr b/tests/test-ws.cr index f4ccabb..0582b29 100644 --- a/tests/test-ws.cr +++ b/tests/test-ws.cr @@ -10,12 +10,12 @@ require "../src/lib_modifications.cr" require "json" class TestIPC - property ipcc : IPC::Connection + property ipcc : IPC::Client property is_json : Bool def initialize(service_name : String) @is_json = uri.ends_with? ".JSON" - @ipcc = IPC::Connection.new service_name + @ipcc = IPC::Client.new service_name end # TODO @@ -60,9 +60,9 @@ class TestWS m : String | Bytes if @is_json - m = IPC::Message.new(1.to_u8, type.to_u8, data).to_json + m = IPC::Message.new(0, 1.to_u8, type.to_u8, data).to_json else - m = IPC::Message.new(1.to_u8, type.to_u8, data).to_packet + m = IPC::Message.new(0, 1.to_u8, type.to_u8, data).to_packet end @ws.send m