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"
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

View File

@ -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

View File

@ -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