The Crystal programming language | http://crystal-lang.org | Fund Crystal's development: http://is.gd/X7PRtI | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/
require "socket"
def process(client)
client.tcp_nodelay = true
while msg = client.gets
client.puts(msg)
end
end
server = TCPServer.new "localhost", 1234
loop { spawn process(server.accept) }
tcp_nodelay = true
dropped the latency from 88ms to 44ms for me.@slava-dzyba how do you test the speed? I get something more like 30-40 nanoseconds for this echo server code. my little tester:
require "socket"
require "benchmark"
client = TCPSocket.new "localhost", 1234
payload = "Hello world" * 1_000
time = Benchmark.measure do
client.puts payload
client.gets
end
puts time
Sample output: 0.000000 0.000000 0.000000 ( 0.000048)
Does anyone have experience working with the parser? There aren't any comments or guides and I would like to make an addition.
Basically, I was thinking it would be cool to be able to splat a tuple just like you can in a method definition, but during multiple assignment. Like this:
head, *tail = {"Seattle", "Hong Kong", "London"}
head # => "Seattle"
tail # => {"Hong Kong", "London"}
def splat(head, *tail)
{head, tail}
end
head, tail = splat(*{"Seattle", "Hong Kong", "London"})
pp head
pp tail
Does anyone have experience working with the parser?
https://github.com/crystal-jp/techbookfest2/tree/master/makenowjust by @MakeNowJust but in Japanesse :sweat_smile: