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

Function Benchmark_Bind_Body_MultipartForm

bind_test.go:1681–1710  ·  view source on GitHub ↗

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

(b *testing.B)

Source from the content-addressed store, hash-verified

1679
1680// go test -v -run=^$ -bench=Benchmark_Bind_Body_MultipartForm -benchmem -count=4
1681func Benchmark_Bind_Body_MultipartForm(b *testing.B) {
1682 var err error
1683
1684 app := New()
1685 c := app.AcquireCtx(&fasthttp.RequestCtx{})
1686
1687 type Demo struct {
1688 Name string `form:"name"`
1689 }
1690
1691 buf := &bytes.Buffer{}
1692 writer := multipart.NewWriter(buf)
1693 require.NoError(b, writer.WriteField("name", "john"))
1694 require.NoError(b, writer.Close())
1695 body := buf.Bytes()
1696
1697 c.Request().SetBody(body)
1698 c.Request().Header.SetContentType(MIMEMultipartForm + `;boundary=` + writer.Boundary())
1699 c.Request().Header.SetContentLength(len(body))
1700 d := new(Demo)
1701
1702 b.ReportAllocs()
1703
1704 for b.Loop() {
1705 err = c.Bind().Body(d)
1706 }
1707
1708 require.NoError(b, err)
1709 require.Equal(b, "john", d.Name)
1710}
1711
1712// go test -v -run=^$ -bench=Benchmark_Bind_Body_MultipartForm_Nested -benchmem -count=4
1713func Benchmark_Bind_Body_MultipartForm_Nested(b *testing.B) {

Callers

nothing calls this directly

Calls 8

BytesMethod · 0.95
AcquireCtxMethod · 0.80
BoundaryMethod · 0.80
NewFunction · 0.70
CloseMethod · 0.65
RequestMethod · 0.65
BodyMethod · 0.65
BindMethod · 0.65

Tested by

no test coverage detected