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

Function Benchmark_Session

middleware/session/session_test.go:1403–1438  ·  view source on GitHub ↗

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

(b *testing.B)

Source from the content-addressed store, hash-verified

1401
1402// go test -v -run=^$ -bench=Benchmark_Session -benchmem -count=4
1403func Benchmark_Session(b *testing.B) {
1404 b.Run("default", func(b *testing.B) {
1405 app, store := fiber.New(), NewStore()
1406 c := app.AcquireCtx(&fasthttp.RequestCtx{})
1407 defer app.ReleaseCtx(c)
1408 c.Request().Header.SetCookie("session_id", "12356789")
1409
1410 b.ReportAllocs()
1411 for b.Loop() {
1412 sess, _ := store.Get(c) //nolint:errcheck // We're inside a benchmark
1413 sess.Set("john", "doe")
1414 _ = sess.Save() //nolint:errcheck // We're inside a benchmark
1415
1416 sess.Release()
1417 }
1418 })
1419
1420 b.Run("storage", func(b *testing.B) {
1421 app := fiber.New()
1422 store := NewStore(Config{
1423 Storage: memory.New(),
1424 })
1425 c := app.AcquireCtx(&fasthttp.RequestCtx{})
1426 defer app.ReleaseCtx(c)
1427 c.Request().Header.SetCookie("session_id", "12356789")
1428
1429 b.ReportAllocs()
1430 for b.Loop() {
1431 sess, _ := store.Get(c) //nolint:errcheck // We're inside a benchmark
1432 sess.Set("john", "doe")
1433 _ = sess.Save() //nolint:errcheck // We're inside a benchmark
1434
1435 sess.Release()
1436 }
1437 })
1438}
1439
1440// go test -v -run=^$ -bench=Benchmark_Session_Parallel -benchmem -count=4
1441func Benchmark_Session_Parallel(b *testing.B) {

Callers

nothing calls this directly

Calls 11

GetMethod · 0.95
NewFunction · 0.92
NewStoreFunction · 0.85
AcquireCtxMethod · 0.80
ReleaseCtxMethod · 0.80
NewMethod · 0.65
RequestMethod · 0.65
SetMethod · 0.65
SetCookieMethod · 0.45
SaveMethod · 0.45
ReleaseMethod · 0.45

Tested by

no test coverage detected