go test -v -run=^$ -bench=Benchmark_Cache -benchmem -count=4
(b *testing.B)
| 3738 | |
| 3739 | // go test -v -run=^$ -bench=Benchmark_Cache -benchmem -count=4 |
| 3740 | func Benchmark_Cache(b *testing.B) { |
| 3741 | app := fiber.New() |
| 3742 | |
| 3743 | app.Use(New()) |
| 3744 | |
| 3745 | app.Get("/demo", func(c fiber.Ctx) error { |
| 3746 | data, _ := os.ReadFile("../../.github/README.md") //nolint:errcheck // We're inside a benchmark |
| 3747 | return c.Status(fiber.StatusTeapot).Send(data) |
| 3748 | }) |
| 3749 | |
| 3750 | h := app.Handler() |
| 3751 | |
| 3752 | fctx := &fasthttp.RequestCtx{} |
| 3753 | fctx.Request.Header.SetMethod(fiber.MethodGet) |
| 3754 | fctx.Request.SetRequestURI("/demo") |
| 3755 | |
| 3756 | b.ReportAllocs() |
| 3757 | |
| 3758 | for b.Loop() { |
| 3759 | h(fctx) |
| 3760 | } |
| 3761 | |
| 3762 | require.Equal(b, fiber.StatusTeapot, fctx.Response.Header.StatusCode()) |
| 3763 | require.Greater(b, len(fctx.Response.Body()), 30000) |
| 3764 | } |
| 3765 | |
| 3766 | func Benchmark_Cache_Miss(b *testing.B) { |
| 3767 | app := fiber.New() |