From f11622e74678f9d1b9082bad103798871591f6d4 Mon Sep 17 00:00:00 2001 From: Marcelo Zimbres Date: Thu, 25 Aug 2022 21:24:23 +0200 Subject: [PATCH] Updates the go benchmark. --- benchmarks/benchmarks.md | 2 +- benchmarks/benchmarks.tex | 8 +++----- benchmarks/go/echo_server_direct.go | 26 ++++++++++++++------------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/benchmarks/benchmarks.md b/benchmarks/benchmarks.md index c2aa6163..68249e41 100644 --- a/benchmarks/benchmarks.md +++ b/benchmarks/benchmarks.md @@ -34,7 +34,7 @@ decrease. * I did expect nodejs to come a little behind given it is is javascript code. Otherwise I did expect it to have similar performance to libuv since it is the framework behind it. - * Go performance did not surprise me: decent and not some much far behind nodejs. + * Go did surprise me: faster than nodejs and liuv! The code used in the benchmarks can be found at diff --git a/benchmarks/benchmarks.tex b/benchmarks/benchmarks.tex index 708fdc74..620814dc 100644 --- a/benchmarks/benchmarks.tex +++ b/benchmarks/benchmarks.tex @@ -17,7 +17,7 @@ width=15cm, height=6cm, enlarge y limits=0.5, title={TCP Echo Server Performance}, xlabel={Seconds}, - symbolic y coords={Asio,Tokio,Libuv,Nodejs,Go}, + symbolic y coords={Asio,Tokio,Go,Libuv,Nodejs}, ytick=data, %bar width=1cm, nodes near coords, @@ -26,18 +26,16 @@ \addplot coordinates { (31.1,Asio) (30.7,Tokio) + (35.6,Go) (43.6,Libuv) (74.2,Nodejs) - (81.0,Go) }; \end{axis} \end{tikzpicture} \endpgfgraphicnamed \beginpgfgraphicnamed{echo-f1} -%debian2[0]$ time ./echo_server_client 1000 1000 -%Go (1): 1.000s -%C++ (1): 0.07s +%$ time ./echo_server_client 1000 1000 \begin{tikzpicture}[scale=1.0] \begin{axis}[ y dir=reverse, diff --git a/benchmarks/go/echo_server_direct.go b/benchmarks/go/echo_server_direct.go index fac10831..070bce70 100644 --- a/benchmarks/go/echo_server_direct.go +++ b/benchmarks/go/echo_server_direct.go @@ -1,29 +1,31 @@ package main import ( - "bufio" "fmt" - "io" "net" "os" + "runtime" ) func echo(conn net.Conn) { - r := bufio.NewReader(conn) + buf := make([]byte, 1024) for { - line, err := r.ReadBytes(byte('\n')) - switch err { - case nil: - break - case io.EOF: - default: - fmt.Println("ERROR", err) - } - conn.Write(line) + n, err := conn.Read(buf) + if err != nil { + break; + } + + conn.Write(buf[:n]) + if err != nil { + fmt.Println("ERROR", err) + os.Exit(1) + } } } func main() { + runtime.GOMAXPROCS(1) + l, err := net.Listen("tcp", "0.0.0.0:55555") if err != nil { fmt.Println("ERROR", err)