-
Notifications
You must be signed in to change notification settings - Fork 5
/
http_test.go
62 lines (47 loc) · 1.08 KB
/
http_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package benchmarks_test
import (
"context"
"fmt"
"net"
"net/http"
"testing"
"github.com/abemedia/go-don"
_ "github.com/abemedia/go-don/encoding/text"
"github.com/gin-gonic/gin"
"github.com/valyala/fasthttp"
)
func BenchmarkDon_HTTP(b *testing.B) {
api := don.New(nil)
api.Get("/:path", don.H(func(ctx context.Context, req any) (string, error) {
return "foo", nil
}))
ln, err := net.Listen("tcp", "localhost:0")
if err != nil {
b.Fatal(err)
}
srv := fasthttp.Server{Handler: api.RequestHandler()}
go srv.Serve(ln)
url := fmt.Sprintf("http://%s/path", ln.Addr())
for i := 0; i < b.N; i++ {
fasthttp.Get(nil, url)
}
srv.Shutdown()
}
func BenchmarkGin_HTTP(b *testing.B) {
gin.SetMode("release")
router := gin.New()
router.GET("/:path", func(c *gin.Context) {
c.String(200, "foo")
})
ln, err := net.Listen("tcp", "localhost:0")
if err != nil {
b.Fatal(err)
}
srv := http.Server{Handler: router}
go srv.Serve(ln)
url := fmt.Sprintf("http://%s/path", ln.Addr())
for i := 0; i < b.N; i++ {
fasthttp.Get(nil, url)
}
srv.Shutdown(context.Background())
}