Skip to content

Instantly share code, notes, and snippets.

@sdogruyol
Created March 28, 2016 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdogruyol/a416a2f82f772753cd66 to your computer and use it in GitHub Desktop.
Save sdogruyol/a416a2f82f772753cd66 to your computer and use it in GitHub Desktop.
require "kemal"
require "benchmark"
def create_ws_request_and_return_io(handler, request)
io = MemoryIO.new
response = HTTP::Server::Response.new(io)
context = HTTP::Server::Context.new(request, response)
begin
handler.call context
rescue IO::Error
# Raises because the MemoryIO is empty
end
response.close
io
end
headers = HTTP::Headers{
"Upgrade": "websocket",
"Connection": "Upgrade",
"Sec-WebSocket-Key": "dGhlIHNhbXBsZSBub25jZQ==",
}
request = HTTP::Request.new("GET", "/", headers)
Benchmark.ips do |x|
x.report "Websocket without ParamParser" do
handler = Kemal::WebSocketHandler.new "/" { }
create_ws_request_and_return_io(handler, request)
end
x.report "Websocket with ParamParser" do
handler = Kemal::WebSocketHandler.new "/" do |socket, env|
param_parser = Kemal::ParamParser.new env.request
end
create_ws_request_and_return_io(handler, request)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment