3
0
websocketd/tests/performances/ipc_message_exchange.cr

47 lines
1000 B
Crystal
Raw Normal View History

2020-07-04 22:31:17 +02:00
require "benchmark"
require "ipc"
require "../test-ws"
ws_uri = "ws://localhost:1234/pong"
2020-07-04 22:31:17 +02:00
ws_uri_json = "ws://localhost:1234/pong.JSON"
2020-07-04 22:31:17 +02:00
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
2020-07-04 22:31:17 +02:00
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
2020-07-04 22:31:17 +02:00
case event
when IPC::Event::MessageSent
# OK
when IPC::Event::MessageReceived
# puts "message received"
break
else
puts "event: #{event}"
end
end
2020-07-04 22:31:17 +02:00
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
2020-07-04 22:31:17 +02:00
bm.report("web sockets + json: round trip time") do
# puts "web sockets + json: round trip time"
2020-07-04 22:31:17 +02:00
ws_pong_json.send 42, "coucou"
m = ws_pong_json.read
end
end