Skip to content

Instantly share code, notes, and snippets.

Created August 23, 2014 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/c90f722ad5e24f2a366e to your computer and use it in GitHub Desktop.
Save anonymous/c90f722ad5e24f2a366e to your computer and use it in GitHub Desktop.
Benchmarking

Rust:

$ wrk --connections 1 --duration 10s --threads 1 http://127.0.0.1:8080
Running 10s test @ http://127.0.0.1:8080
  1 threads and 1 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     8.31us    9.04us   1.11ms   98.17%
    Req/Sec    40.61k     2.73k   45.11k    71.37%
  375419 requests in 10.00s, 35.80MB read
  Socket errors: connect 0, read 288486, write 86932, timeout 0
Requests/sec:  37542.20
Transfer/sec:      3.58MB

Go:

$ wrk --connections 1 --duration 10s --threads 1 http://127.0.0.1:8080
Running 10s test @ http://127.0.0.1:8080
  1 threads and 1 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     8.94us    7.68us   1.47ms   96.60%
    Req/Sec    34.14k     2.33k   38.33k    71.97%
  318339 requests in 10.00s, 30.36MB read
  Socket errors: connect 0, read 282440, write 35898, timeout 0
Requests/sec:  31834.19
Transfer/sec:      3.04MB
package main
import (
"fmt"
"net"
"os"
)
func handle_client(conn net.Conn) {
response := []byte("HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\ncontent-length: 21\r\n\r\n<h1>Test content</h1>")
_, err := conn.Write(response)
if err != nil {
fmt.Printf("Failed sending response: {}!\n", err.Error())
}
conn.Close()
}
func main() {
l, err := net.Listen("tcp", "127.0.0.1:8080")
if err != nil {
fmt.Printf("Error listening: %s\n", err.Error())
os.Exit(1)
}
defer l.Close()
fmt.Printf("Listening for connections on port %d\n", 8080)
for {
conn, err := l.Accept()
if err != nil {
fmt.Printf("Failed sending response: %s!\n", err.Error())
continue
}
go handle_client(conn)
}
}
use std::io::net::tcp::{TcpListener, TcpStream};
use std::io::{Acceptor, Listener};
fn handle_client(mut stream: TcpStream) {
let response = b"HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\ncontent-length: 21\r\n\r\n<h1>Test content</h1>";
match stream.write(response) {
Ok(()) => (),
Err(e) => println!("Failed sending response: {}!", e),
}
}
fn main() {
let listener = TcpListener::bind("127.0.0.1", 8080);
let mut acceptor = listener.listen();
println!("Listening for connections on port {}", 8080i);
for stream in acceptor.incoming() {
match stream {
Err(e) => println!("Failed sending response: {}!", e),
Ok(stream) => spawn(proc() {
handle_client(stream)
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment