-
Notifications
You must be signed in to change notification settings - Fork 64
/
server_test.go
44 lines (40 loc) · 979 Bytes
/
server_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package server
import (
"io/ioutil"
"net"
"testing"
)
func init() {
// to avoid recreating servers that listen on the same address
// inside each benchmark
plainServer().Wait()
poolServer().Wait()
}
// to run the benchmark run the following
// go test -benchtime=3s -bench=.
func BenchmarkPlainServer(b *testing.B) {
for i := 0; i < b.N; i++ {
conn, err := net.Dial("tcp", ":8080")
if err != nil {
b.Fatalf("could not dial host: %v", err)
}
if _, err := ioutil.ReadAll(conn); err != nil {
b.Fatalf("could not read from connection: %v", err)
}
_ = conn.Close()
}
}
// to run the benchmark run the following
// go test -benchtime=3s -bench=.
func BenchmarkPoolServer(b *testing.B) {
for i := 0; i < b.N; i++ {
conn, err := net.Dial("tcp", ":9090")
if err != nil {
b.Fatalf("could not dial host: %v", err)
}
if _, err := ioutil.ReadAll(conn); err != nil {
b.Fatalf("could not read from connection: %v", err)
}
_ = conn.Close()
}
}