Last active
October 10, 2015 09:03
-
-
Save chinghanho/a2b576e37ac8615b30ec to your computer and use it in GitHub Desktop.
Simple benchmark of plain text in Go, Ruby, PHP and Node.js
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
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
) | |
func rootHandler(w http.ResponseWriter, r *http.Request) { | |
w.WriteHeader(200) | |
fmt.Fprint(w, "Hello, world!") | |
} | |
func main() { | |
http.HandleFunc("/", rootHandler) | |
log.Fatal(http.ListenAndServe(":9090", nil)) | |
} | |
// Running 30s test @ http://localhost:9090 | |
// 4 threads and 400 connections | |
// Thread Stats Avg Stdev Max +/- Stdev | |
// Latency 5.57ms 7.01ms 125.35ms 90.34% | |
// Req/Sec 10.02k 2.24k 29.71k 74.53% | |
// 1193942 requests in 30.10s, 148.02MB read | |
// Socket errors: connect 0, read 259, write 1, timeout 1 | |
// Requests/sec: 39669.52 | |
// Transfer/sec: 4.92MB |
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
var http = require('http') | |
var counter = 0 | |
var server = http.createServer(function (req, res) { | |
res.writeHead(200) | |
if (req.url !== '/favicon.ico') ++counter | |
res.end('counter: ' + counter) | |
}) | |
server.listen(3333) | |
// Running 30s test @ http://localhost:3333 | |
// 4 threads and 400 connections | |
// Thread Stats Avg Stdev Max +/- Stdev | |
// Latency 57.77ms 7.18ms 237.45ms 89.99% | |
// Req/Sec 1.72k 199.45 2.52k 80.58% | |
// 205768 requests in 30.08s, 25.99MB read | |
// Socket errors: connect 0, read 206, write 13, timeout 0 | |
// Requests/sec: 6839.64 | |
// Transfer/sec: 0.86MB |
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
<?php | |
set_time_limit(0); | |
$address = '127.0.0.1'; | |
$port = 8000; | |
$sock = socket_create(AF_INET, SOCK_STREAM, 0); | |
socket_bind($sock, $address, $port) or die('Could not bind to address'); | |
$counter = 0; | |
while(1) { | |
socket_listen($sock); | |
$client = socket_accept($sock); | |
$input = socket_read($client, 1024); | |
$incoming = array(); | |
$incoming = explode("\r\n", $input); | |
$fetchArray = array(); | |
$fetchArray = explode(" ", $incoming[0]); | |
$output = ""; | |
$Header = "HTTP/1.1 200 OK \r\n" . | |
"Date: Fri, 31 Dec 1999 23:59:59 GMT \r\n" . | |
"Content-Type: text/html \r\n\r\n"; | |
$counter = $counter + 1; | |
$content = "counter: ". $counter; | |
$output = $Header . $content; | |
socket_write($client,$output,strlen($output)); | |
socket_close($client); | |
} | |
// Running 30s test @ http://localhost:8000 | |
// 4 threads and 400 connections | |
// Thread Stats Avg Stdev Max +/- Stdev | |
// Latency 16.85ms 4.47ms 42.82ms 75.70% | |
// Req/Sec 1.02k 431.79 1.61k 75.61% | |
// 16710 requests in 30.03s, 1.55MB read | |
// Socket errors: connect 0, read 753, write 0, timeout 0 | |
// Requests/sec: 556.51 | |
// Transfer/sec: 52.90KB |
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 'socket' | |
require 'uri' | |
server = TCPServer.new('localhost', 2345) | |
counter = 0 | |
loop do | |
socket = server.accept | |
request = socket.gets || "GET / HTTP/1.1" | |
request_uri = request.split(" ")[1] | |
path = URI.unescape(URI(request_uri).path) | |
counter += 1 unless path == "/favicon.ico" | |
response = "counter: #{counter}\n" | |
socket.print "HTTP/1.1 200 OK\r\n" + | |
"Content-Type: text/plain\r\n" + | |
"Content-Length: #{response.bytesize}\r\n" + | |
"Connection: close\r\n" | |
socket.print "\r\n" | |
socket.print response | |
socket.close | |
end | |
# Running 30s test @ http://localhost:2345 | |
# 4 threads and 400 connections | |
# Thread Stats Avg Stdev Max +/- Stdev | |
# Latency 22.25ms 29.22ms 315.84ms 94.62% | |
# Req/Sec 499.46 453.80 1.37k 53.46% | |
# 16531 requests in 30.06s, 1.55MB read | |
# Socket errors: connect 0, read 768, write 0, timeout 0 | |
# Requests/sec: 550.02 | |
# Transfer/sec: 52.82KB |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment