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

Function Benchmark_Session_Parallel

middleware/session/session_test.go:1441–1484  ·  view source on GitHub ↗

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

(b *testing.B)

Source from the content-addressed store, hash-verified

1439
1440// go test -v -run=^$ -bench=Benchmark_Session_Parallel -benchmem -count=4
1441func Benchmark_Session_Parallel(b *testing.B) {
1442 b.Run("default", func(b *testing.B) {
1443 app, store := fiber.New(), NewStore()
1444 b.ReportAllocs()
1445 b.ResetTimer()
1446 b.RunParallel(func(pb *testing.PB) {
1447 for pb.Next() {
1448 c := app.AcquireCtx(&fasthttp.RequestCtx{})
1449 c.Request().Header.SetCookie("session_id", "12356789")
1450
1451 sess, _ := store.Get(c) //nolint:errcheck // We're inside a benchmark
1452 sess.Set("john", "doe")
1453 _ = sess.Save() //nolint:errcheck // We're inside a benchmark
1454
1455 sess.Release()
1456
1457 app.ReleaseCtx(c)
1458 }
1459 })
1460 })
1461
1462 b.Run("storage", func(b *testing.B) {
1463 app := fiber.New()
1464 store := NewStore(Config{
1465 Storage: memory.New(),
1466 })
1467 b.ReportAllocs()
1468 b.ResetTimer()
1469 b.RunParallel(func(pb *testing.PB) {
1470 for pb.Next() {
1471 c := app.AcquireCtx(&fasthttp.RequestCtx{})
1472 c.Request().Header.SetCookie("session_id", "12356789")
1473
1474 sess, _ := store.Get(c) //nolint:errcheck // We're inside a benchmark
1475 sess.Set("john", "doe")
1476 _ = sess.Save() //nolint:errcheck // We're inside a benchmark
1477
1478 sess.Release()
1479
1480 app.ReleaseCtx(c)
1481 }
1482 })
1483 })
1484}
1485
1486// go test -v -run=^$ -bench=Benchmark_Session_Asserted -benchmem -count=4
1487func Benchmark_Session_Asserted(b *testing.B) {

Callers

nothing calls this directly

Calls 12

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

Tested by

no test coverage detected