MCPcopy
hub / github.com/gofiber/fiber / Benchmark_Cache

Function Benchmark_Cache

middleware/cache/cache_test.go:3740–3764  ·  view source on GitHub ↗

go test -v -run=^$ -bench=Benchmark_Cache -benchmem -count=4

(b *testing.B)

Source from the content-addressed store, hash-verified

3738
3739// go test -v -run=^$ -bench=Benchmark_Cache -benchmem -count=4
3740func 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
3766func Benchmark_Cache_Miss(b *testing.B) {
3767 app := fiber.New()

Callers

nothing calls this directly

Calls 10

HandlerMethod · 0.80
SetMethodMethod · 0.80
NewFunction · 0.70
NewMethod · 0.65
UseMethod · 0.65
GetMethod · 0.65
SendMethod · 0.65
StatusMethod · 0.65
BodyMethod · 0.65
StatusCodeMethod · 0.45

Tested by

no test coverage detected