Skip to content

Instantly share code, notes, and snippets.

@Papierkorb
Last active February 14, 2017 17:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Papierkorb/f253edb22df08a13e6d8cba9f44cbc00 to your computer and use it in GitHub Desktop.
Save Papierkorb/f253edb22df08a13e6d8cba9f44cbc00 to your computer and use it in GitHub Desktop.
require "socket"
require "benchmark"
socket = TCPSocket.new "localhost", 8081
# socket.tcp_nodelay = true
# socket.sync = true
data = Bytes.new 20
Benchmark.ips do |x|
x.report("ping") do
socket.write data
socket.read_fully data
end
end
require "socket"
server = TCPServer.new "localhost", 8081
buf = Bytes.new 20
while socket = server.accept
# socket.tcp_nodelay = true
# socket.sync = true
spawn do
begin
loop do
socket.read_fully buf
spawn do
socket.write buf
end
end
ensure
socket.close
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment