go test -v -run=^$ -bench=Benchmark_Bind_Cookie -benchmem -count=4
(b *testing.B)
| 2153 | |
| 2154 | // go test -v -run=^$ -bench=Benchmark_Bind_Cookie -benchmem -count=4 |
| 2155 | func Benchmark_Bind_Cookie(b *testing.B) { |
| 2156 | var err error |
| 2157 | |
| 2158 | app := New() |
| 2159 | c := app.AcquireCtx(&fasthttp.RequestCtx{}) |
| 2160 | |
| 2161 | type Cookie struct { |
| 2162 | Name string |
| 2163 | Hobby []string |
| 2164 | ID int |
| 2165 | } |
| 2166 | c.Request().SetBody([]byte(``)) |
| 2167 | c.Request().Header.SetContentType("") |
| 2168 | |
| 2169 | c.Request().Header.SetCookie("id", "1") |
| 2170 | c.Request().Header.SetCookie("Name", "John Doe") |
| 2171 | c.Request().Header.SetCookie("Hobby", "golang,fiber") |
| 2172 | |
| 2173 | q := new(Cookie) |
| 2174 | b.ReportAllocs() |
| 2175 | |
| 2176 | for b.Loop() { |
| 2177 | err = c.Bind().Cookie(q) |
| 2178 | } |
| 2179 | require.NoError(b, err) |
| 2180 | } |
| 2181 | |
| 2182 | // go test -v -run=^$ -bench=Benchmark_Bind_Cookie_Map -benchmem -count=4 |
| 2183 | func Benchmark_Bind_Cookie_Map(b *testing.B) { |