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

Function Benchmark_Cache_Storage

middleware/cache/cache_test.go:3796–3822  ·  view source on GitHub ↗

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

(b *testing.B)

Source from the content-addressed store, hash-verified

3794
3795// go test -v -run=^$ -bench=Benchmark_Cache_Storage -benchmem -count=4
3796func Benchmark_Cache_Storage(b *testing.B) {
3797 app := fiber.New()
3798
3799 app.Use(New(Config{
3800 Storage: memory.New(),
3801 }))
3802
3803 app.Get("/demo", func(c fiber.Ctx) error {
3804 data, _ := os.ReadFile("../../.github/README.md") //nolint:errcheck // We're inside a benchmark
3805 return c.Status(fiber.StatusTeapot).Send(data)
3806 })
3807
3808 h := app.Handler()
3809
3810 fctx := &fasthttp.RequestCtx{}
3811 fctx.Request.Header.SetMethod(fiber.MethodGet)
3812 fctx.Request.SetRequestURI("/demo")
3813
3814 b.ReportAllocs()
3815
3816 for b.Loop() {
3817 h(fctx)
3818 }
3819
3820 require.Equal(b, fiber.StatusTeapot, fctx.Response.Header.StatusCode())
3821 require.Greater(b, len(fctx.Response.Body()), 30000)
3822}
3823
3824func Benchmark_Cache_AdditionalHeaders(b *testing.B) {
3825 app := fiber.New()

Callers

nothing calls this directly

Calls 11

NewFunction · 0.92
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