Skip to content

Commit b6723a7

Browse files
gabyefectn
authored andcommitted
🧹 chore: Add Immutable benchmarks for default case (gofiber#3374)
Add benchmarks for default case with Immutable
1 parent 9c10d0d commit b6723a7

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

router_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,50 @@ func Benchmark_Router_Next_Default_Parallel(b *testing.B) {
11021102
})
11031103
}
11041104

1105+
// go test -v ./... -run=^$ -bench=Benchmark_Router_Next_Default_Immutable -benchmem -count=4
1106+
func Benchmark_Router_Next_Default_Immutable(b *testing.B) {
1107+
app := New(Config{Immutable: true})
1108+
app.Get("/", func(_ Ctx) error {
1109+
return nil
1110+
})
1111+
1112+
h := app.Handler()
1113+
1114+
fctx := &fasthttp.RequestCtx{}
1115+
fctx.Request.Header.SetMethod(MethodGet)
1116+
fctx.Request.SetRequestURI("/")
1117+
1118+
b.ReportAllocs()
1119+
b.ResetTimer()
1120+
1121+
for n := 0; n < b.N; n++ {
1122+
h(fctx)
1123+
}
1124+
}
1125+
1126+
// go test -benchmem -run=^$ -bench ^Benchmark_Router_Next_Default_Parallel_Immutable$ github.com/gofiber/fiber/v3 -count=1
1127+
func Benchmark_Router_Next_Default_Parallel_Immutable(b *testing.B) {
1128+
app := New(Config{Immutable: true})
1129+
app.Get("/", func(_ Ctx) error {
1130+
return nil
1131+
})
1132+
1133+
h := app.Handler()
1134+
1135+
b.ReportAllocs()
1136+
b.ResetTimer()
1137+
1138+
b.RunParallel(func(pb *testing.PB) {
1139+
fctx := &fasthttp.RequestCtx{}
1140+
fctx.Request.Header.SetMethod(MethodGet)
1141+
fctx.Request.SetRequestURI("/")
1142+
1143+
for pb.Next() {
1144+
h(fctx)
1145+
}
1146+
})
1147+
}
1148+
11051149
// go test -v ./... -run=^$ -bench=Benchmark_Route_Match -benchmem -count=4
11061150
func Benchmark_Route_Match(b *testing.B) {
11071151
var match bool

0 commit comments

Comments
 (0)