MCPcopy
hub / github.com/danielgtaylor/huma / BenchmarkSchemaGeneration

Function BenchmarkSchemaGeneration

bench_test.go:84–114  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

82}
83
84func BenchmarkSchemaGeneration(b *testing.B) {
85 t := reflect.TypeFor[BenchComplex]()
86
87 b.Run("NewRegistry", func(b *testing.B) {
88 b.ReportAllocs()
89 for i := 0; i < b.N; i++ {
90 // Create a new registry each time to measure generation cost.
91 reg := huma.NewMapRegistry("#/components/schemas/", huma.DefaultSchemaNamer)
92 huma.SchemaFromType(reg, t)
93 }
94 })
95
96 b.Run("ReusedRegistry", func(b *testing.B) {
97 reg := huma.NewMapRegistry("#/components/schemas/", huma.DefaultSchemaNamer)
98 b.ReportAllocs()
99 for i := 0; i < b.N; i++ {
100 // Reuse the registry to see the cost of lookup/caching.
101 huma.SchemaFromType(reg, t)
102 }
103 })
104
105 b.Run("RegistryLookup", func(b *testing.B) {
106 reg := huma.NewMapRegistry("#/components/schemas/", huma.DefaultSchemaNamer)
107 reg.Schema(t, true, "") // initial registration
108 b.ReportAllocs()
109 for i := 0; i < b.N; i++ {
110 // Measure the cost of a simple lookup for a registered struct.
111 reg.Schema(t, true, "")
112 }
113 })
114}
115
116func BenchmarkValidate_Complex(b *testing.B) {
117 registry := huma.NewMapRegistry("#/components/schemas/", huma.DefaultSchemaNamer)

Callers

nothing calls this directly

Calls 2

RunMethod · 0.65
SchemaMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…