Skip to content

Instantly share code, notes, and snippets.

View sdogruyol's full-sized avatar
🏠
Working from home

Serdar Dogruyol - Sedo セド sdogruyol

🏠
Working from home
View GitHub Profile
# Type inferred
def say(something)
p something
end
# Explicit Type
def say(something : String)
p something
end
@sdogruyol
sdogruyol / crystal_chat.cr
Created December 14, 2015 19:12
Simple Crystal Chat Server
require "http/server"
SOCKETS = [] of HTTP::WebSocketHandler::WebSocketSession
ws_handler = HTTP::WebSocketHandler.new do |socket|
puts "Socket opened"
SOCKETS << socket
socket.on_message do |message|
SOCKETS.each { |socket| socket.send "Echo back from server: #{message}" }

Crystal vs Node.js Websocket Benchmark

Crystal 0.9.1 with Kemal

require "kemal"

ws "/" do |socket|
  socket.on_message do |message|
 end
@sdogruyol
sdogruyol / http-server-benchmark.md
Last active December 27, 2015 00:09
fast-http-server (https://github.com/sdogruyol/fast-http-server) performance benchmark.

This is done with a demo bootstrap static site which includes js, css

wrk is used for benchmarking with

wrk -c 100 -d 20 http://localhost:3000

Fast

Numbers speak louder than words.

Kemal vs Sinatra Benchmark

This is just for demonstration purpose. A simple app just returning "Hello World". First in Kemal (Crystal) and then in Sinatra(Ruby with thin).

Kemal (Crystal)

Kemal Version: 0.6.0 Crystal Version: 0.10.0

Kemal Crystal v0.10.0 vs new-fibers

This benchmark demonstrates the new-fibers improvements via Kemal.

# app.cr
require "kemal"

get "/" do
 "Hello World"
require "kemal"
logging false
# OAuth Authorizations
get "/authorizations" do
""
end
get "/authorizations/:id" do
""
require "kemal"
logging false
get "/" do
"Hello World!"
end
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
require "benchmark"
require "json"
class MenuItem
def self.all
h = {
"name": "Serdar",
"age": 27,
"email": "dogruyolserdar@gmail.com",