let server = http.newServer()
server.address = ":8081"
server.handler = (w, r) => w.write("Hello, World!")
server.start()
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello, world!")
})
http.ListenAndServe(":8082", nil)
}
Using lwan webserver
#include "lwan.h"
LWAN_HANDLER(hello_world)
{
static const char message[] = "Hello, World!";
response->mime_type = "text/plain";
lwan_strbuf_set_static(response->buffer, message, sizeof(message) - 1);
return HTTP_OK;
}
int
main(void)
{
const struct lwan_url_map default_map[] = {
{ .prefix = "/", .handler = LWAN_HANDLER_REF(hello_world) },
{ .prefix = NULL }
};
struct lwan l;
lwan_init(&l);
lwan_set_url_map(&l, default_map);
lwan_main_loop(&l);
lwan_shutdown(&l);
return 0;
}
# dune
$ wrk -d2 http://localhost:8082
Running 2s test @ http://localhost:8082
2 threads and 10 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 42.70us 109.53us 8.64ms 98.35%
Req/Sec 120.04k 4.71k 144.42k 85.37%
489385 requests in 2.10s, 60.67MB read
Requests/sec: 233108.97
Transfer/sec: 28.90MB
# go
$ wrk -d2 http://localhost:8082
Running 2s test @ http://localhost:8082
2 threads and 10 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 39.74us 48.04us 2.54ms 96.61%
Req/Sec 123.54k 4.68k 147.08k 87.80%
503408 requests in 2.10s, 62.41MB read
Requests/sec: 239800.20
Transfer/sec: 29.73MB
# c
$ wrk -d2 http://localhost:8081
Running 2s test @ http://localhost:8081
2 threads and 10 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 47.89us 67.63us 2.69ms 94.83%
Req/Sec 112.09k 3.09k 118.21k 78.57%
467756 requests in 2.10s, 57.99MB read
Requests/sec: 222742.86
Transfer/sec: 27.62MB