Created
March 28, 2016 14:06
-
-
Save sdogruyol/a416a2f82f772753cd66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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