Dart vs Go
Dartlang vs Golang
HTTP performance
A simple test
server.dart
| 
					 1 2 3 4 5 6 7 8 9 10  | 
						import 'dart:io'; void main() {   HttpServer.bind('localhost', 8080).then((server) {     server.listen((request) {       request.response.write('Hello World');       request.response.close();     });   }); }  | 
					
main.go
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13  | 
						package main import (         "fmt"         "net/http" ) func main() {         http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {                 fmt.Fprintln(w, "Hello World")         })         http.ListenAndServe(":8080", nil) }  | 
					
Dart v2.5.2
Go v1.13.1
OS: Linux
Test runner: wrk
Threads: 4
Duration: 30 seconds
Concurrency: 1000
Results:
I wrote this blog post because I could not find a proper result for “Dart vs Go performance”.
So there you have it
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  | 
						Dart Hello World Running 30s test @ http://localhost:8080/   4 threads and 1000 connections   Thread Stats   Avg      Stdev     Max   +/- Stdev     Latency    55.61ms   74.74ms   1.99s    99.06%     Req/Sec     4.81k   541.03     6.67k    79.77%   572330 requests in 30.03s, 111.35MB read   Socket errors: connect 0, read 0, write 0, timeout 250 Requests/sec:  19056.97 Transfer/sec:      3.71MB Go Hello World Running 30s test @ http://localhost:8080/   4 threads and 1000 connections   Thread Stats   Avg      Stdev     Max   +/- Stdev     Latency     7.59ms   31.93ms 969.90ms   99.43%     Req/Sec    42.64k     6.97k   69.54k    70.29%   5068937 requests in 30.05s, 633.27MB read Requests/sec: 168670.12 Transfer/sec:     21.07MB  | 
					
I believe it’s a pretty large score 1:0 for Go on the server side in terms of performance.
Updated on 26 July 2020:
Dart VM version: 2.8.4 (stable) (Wed Jun 3 12:26:04 2020 +0200) on “linux_x64”
go version go1.14.5 linux/amd64
changed Go code to utilize only 1 cpu
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  | 
						package main import ( 	"fmt" 	"net/http" 	"runtime" ) func main() { 	runtime.GOMAXPROCS(1) 	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 		fmt.Fprintln(w, "Hello World") 	}) 	http.ListenAndServe(":8080", nil) }  | 
					
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  | 
						Go 1 Thread Performance Running 30s test @ http://localhost:8080/   4 threads and 1000 connections   Thread Stats   Avg      Stdev     Max   +/- Stdev     Latency    20.09ms    6.81ms 227.71ms   94.22%     Req/Sec    12.62k     1.01k   15.67k    68.65%   1501337 requests in 30.06s, 184.70MB read Requests/sec:  49949.34 Transfer/sec:      6.14MB Dart Performance Running 30s test @ http://localhost:8080/   4 threads and 1000 connections   Thread Stats   Avg      Stdev     Max   +/- Stdev     Latency    49.51ms   83.87ms   2.00s    98.76%     Req/Sec     5.51k     0.86k    7.99k    88.13%   656185 requests in 30.03s, 127.66MB read   Socket errors: connect 0, read 0, write 0, timeout 317 Requests/sec:  21854.54 Transfer/sec:      4.25MB  | 
					
Still a pretty big 1:0 for Go
Note: The 2 tests were done one 2 different machines.


Great, thanks for this little comparison 😉
This was the best Go vs Dart comparison. Good job mate!
I think this is an unfair comparison because the go code is multi-threaded but the dart code isn’t, as the HTTP server is a very basic implementation.
I found a framework that is supposed to be multi-threaded (https://aqueduct.io/) and did a simple test with it and it is a bit better (my results with the same test as in here were ~200k req/s for go and ~10k req/s for the implementation here, and ~35k req/s for aqueduct with 4 threads too). Another catch is dart can be compiled to native code or run a VM, but not all packages work compiled as native code, and this aqueduct framework uses one of them so I had to do the test in the VM.
Because of this I tried (very hard) to do a simple implementation using a pool of Isolates (threads) with plain dart but failed, mainly because isolate can only communicate via messages that can only be of primitive types (int, String, etc.), so I can’t really reply to requests in other threads.
I was really interested in knowing how dart performance compares to go, and this was an interesting example. It’s a bit sad to realize that dart isn’t even capable to offer a multi-threading flexible enough to implement a decent web server…
Thank you for your insights, Luca. I have added new results with a GOMAXPROCS=1 in Go’s case.