package wire import ( "encoding/json" "testing" "git.flytoex.net/yuanwei/flyto-agent/pkg/flyto" ) // --- AdaptSchema benchmarks --- func BenchmarkAdaptSchema(b *testing.B) { simpleSchema := json.RawMessage(`{ "type": "object", "properties": { "name": {"type": "string"}, "age": {"type": "integer"} }, "required": ["name"] }`) nestedSchema := json.RawMessage(`{ "type": "object", "properties": { "user": { "type": "object", "properties": { "name": {"type": "string"}, "address": { "type": "object", "properties": { "street": {"type": "string"}, "city": {"type": "string"}, "zip": {"type": "string"} } } } }, "items": { "type": "array", "items": { "type": "object", "properties": { "id": {"type": "integer"}, "label": {"type": "string"} } } } } }`) refSchema := json.RawMessage(`{ "type": "object", "$defs": { "Address": { "type": "object", "properties": { "street": {"type": "string"}, "city": {"type": "string"} } } }, "properties": { "home": {"$ref": "#/$defs/Address"}, "work": {"$ref": "#/$defs/Address"} } }`) providers := []string{"anthropic", "openai", "gemini", "minimax"} for _, provider := range providers { b.Run("simple/"+provider, func(b *testing.B) { b.ReportAllocs() for b.Loop() { AdaptSchema(simpleSchema, provider) } }) } b.Run("nested/anthropic", func(b *testing.B) { b.ReportAllocs() for b.Loop() { AdaptSchema(nestedSchema, "anthropic") } }) b.Run("ref_dedup/gemini", func(b *testing.B) { b.ReportAllocs() for b.Loop() { AdaptSchema(refSchema, "gemini") } }) } // --- flytoMessagesToOpenAI benchmarks --- func BenchmarkFlytoMessagesToOpenAI(b *testing.B) { for _, n := range []int{10, 50, 100} { msgs := make([]flyto.Message, n) for i := range msgs { if i%2 == 0 { msgs[i] = flyto.UserText("What is the meaning of life?") } else { msgs[i] = flyto.AssistantText("42, according to Deep Thought.") } } b.Run(intToLabel(n), func(b *testing.B) { b.ReportAllocs() for b.Loop() { flytoMessagesToOpenAI(msgs, "You are a helpful assistant.", false) } }) } } func BenchmarkFlytoMessagesToGemini(b *testing.B) { for _, n := range []int{10, 50, 100} { msgs := make([]flyto.Message, n) for i := range msgs { if i%2 == 0 { msgs[i] = flyto.UserText("Hello") } else { msgs[i] = flyto.AssistantText("Hi there") } } b.Run(intToLabel(n), func(b *testing.B) { b.ReportAllocs() for b.Loop() { flytoMessagesToGemini(msgs) } }) } } func intToLabel(n int) string { switch n { case 10: return "10_msgs" case 50: return "50_msgs" default: return "100_msgs" } }