Home / Function/ Benchmark_Ctx_Format() — fiber Function Reference

Benchmark_Ctx_Format() — fiber Function Reference

Architecture documentation for the Benchmark_Ctx_Format() function in ctx_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  809d4f1b_7c6f_2b2d_fb44_87d9821e52d3["Benchmark_Ctx_Format()"]
  7b3d4933_5ae3_f84d_ff6d_0cb34e268026["ctx_test.go"]
  809d4f1b_7c6f_2b2d_fb44_87d9821e52d3 -->|defined in| 7b3d4933_5ae3_f84d_ff6d_0cb34e268026
  style 809d4f1b_7c6f_2b2d_fb44_87d9821e52d3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

ctx_test.go lines 1799–1875

func Benchmark_Ctx_Format(b *testing.B) {
	app := New()
	c := app.AcquireCtx(&fasthttp.RequestCtx{})
	c.Request().Header.Set(HeaderAccept, "application/json,text/plain; format=flowed; q=0.9")

	fail := func(_ Ctx) error {
		require.FailNow(b, "Wrong type chosen")
		return errors.New("Wrong type chosen")
	}
	ok := func(_ Ctx) error {
		return nil
	}

	var err error
	b.Run("with arg allocation", func(b *testing.B) {
		for b.Loop() {
			err = c.Format(
				ResFmt{MediaType: "application/xml", Handler: fail},
				ResFmt{MediaType: "text/html", Handler: fail},
				ResFmt{MediaType: "text/plain;format=fixed", Handler: fail},
				ResFmt{MediaType: "text/plain;format=flowed", Handler: ok},
			)
		}
		require.NoError(b, err)
	})

	b.Run("pre-allocated args", func(b *testing.B) {
		offers := []ResFmt{
			{MediaType: "application/xml", Handler: fail},
			{MediaType: "text/html", Handler: fail},
			{MediaType: "text/plain;format=fixed", Handler: fail},
			{MediaType: "text/plain;format=flowed", Handler: ok},
		}
		for b.Loop() {
			err = c.Format(offers...)
		}
		require.NoError(b, err)
	})

	c.Request().Header.Set("Accept", "text/plain")
	b.Run("text/plain", func(b *testing.B) {
		offers := []ResFmt{
			{MediaType: "application/xml", Handler: fail},
			{MediaType: "text/plain", Handler: ok},
		}
		for b.Loop() {
			err = c.Format(offers...)
		}
		require.NoError(b, err)
	})

	c.Request().Header.Set("Accept", "json")
	b.Run("json", func(b *testing.B) {
		offers := []ResFmt{
			{MediaType: "xml", Handler: fail},
			{MediaType: "html", Handler: fail},
			{MediaType: "json", Handler: ok},
		}
		for b.Loop() {
			err = c.Format(offers...)
		}
		require.NoError(b, err)
	})

	c.Request().Header.Set("Accept", MIMEApplicationMsgPack)
	b.Run("msgpack", func(b *testing.B) {
		offers := []ResFmt{
			{MediaType: "xml", Handler: fail},
			{MediaType: "html", Handler: fail},
			{MediaType: MIMEApplicationMsgPack, Handler: ok},
		}
		for b.Loop() {
			err = c.Format(offers...)
		}
		require.NoError(b, err)
	})
}

Domain

Subdomains

Defined In

Frequently Asked Questions

What does Benchmark_Ctx_Format() do?
Benchmark_Ctx_Format() is a function in the fiber codebase, defined in ctx_test.go.
Where is Benchmark_Ctx_Format() defined?
Benchmark_Ctx_Format() is defined in ctx_test.go at line 1799.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free