3
0
Fork 0

Performance tests.

dev
Karchnu 2020-07-23 01:08:36 +02:00
parent 3986187c2c
commit 3d0687554b
3 changed files with 36 additions and 23 deletions

View File

@ -5,19 +5,13 @@ require "../test-ws"
ws_uri = "ws://localhost:1234/pong.JSON" ws_uri = "ws://localhost:1234/pong.JSON"
message = IPC::Message.from_json(%({ "mtype" : 3, "utype" : 30, "payload" : "coucou" })) message = IPC::Message.from_json(%({ "mtype" : 3, "utype" : 30, "payload" : "coucou" }))
pong = IPC::Connection.new "pong"
Benchmark.ips do |bm| Benchmark.ips do |bm|
bm.report("connection") do 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
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

View File

@ -2,25 +2,44 @@ require "benchmark"
require "ipc" require "ipc"
require "../test-ws" require "../test-ws"
ws_uri = "ws://localhost:1234/pong" ws_uri = "ws://localhost:1234/pong"
ws_uri_json = "ws://localhost:1234/pong.JSON" ws_uri_json = "ws://localhost:1234/pong.JSON"
ws_pong = TestWS.new ws_uri ws_pong = TestWS.new ws_uri
ws_pong_json = TestWS.new ws_uri_json 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| Benchmark.ips do |bm|
bm.report("direct: round trip time") do bm.report("direct: round trip time") do
pong.send 42, "coucou" # puts "direct: round trip time"
m = pong.read 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 end
bm.report("web sockets: round trip time") do #bm.report("web sockets: round trip time") do
ws_pong.send 42, "coucou" # # puts "web sockets: round trip time"
m = ws_pong.read # ws_pong.send 42, "coucou"
end # m = ws_pong.read
#end
bm.report("web sockets + json: round trip time") do bm.report("web sockets + json: round trip time") do
# puts "web sockets + json: round trip time"
ws_pong_json.send 42, "coucou" ws_pong_json.send 42, "coucou"
m = ws_pong_json.read m = ws_pong_json.read
end end

View File

@ -10,12 +10,12 @@ require "../src/lib_modifications.cr"
require "json" require "json"
class TestIPC class TestIPC
property ipcc : IPC::Connection property ipcc : IPC::Client
property is_json : Bool property is_json : Bool
def initialize(service_name : String) def initialize(service_name : String)
@is_json = uri.ends_with? ".JSON" @is_json = uri.ends_with? ".JSON"
@ipcc = IPC::Connection.new service_name @ipcc = IPC::Client.new service_name
end end
# TODO # TODO
@ -60,9 +60,9 @@ class TestWS
m : String | Bytes m : String | Bytes
if @is_json 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 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 end
@ws.send m @ws.send m