3
0
Fork 0
websocketd/tests/performances/ipc_message_exchange.cr

47 lines
1000 B
Crystal

require "benchmark"
require "ipc"
require "../test-ws"
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::Client.new "pong"
pong.base_timer = 100_000
pong.timer = 100_000
Benchmark.ips do |bm|
bm.report("direct: round trip time") do
# 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
# # 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
end