| 82 | } |
| 83 | |
| 84 | func 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 | |
| 116 | func BenchmarkValidate_Complex(b *testing.B) { |
| 117 | registry := huma.NewMapRegistry("#/components/schemas/", huma.DefaultSchemaNamer) |