go test -v -run=^$ -bench=Benchmark_Session -benchmem -count=4
(b *testing.B)
| 1401 | |
| 1402 | // go test -v -run=^$ -bench=Benchmark_Session -benchmem -count=4 |
| 1403 | func 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 |
| 1441 | func Benchmark_Session_Parallel(b *testing.B) { |