BenchmarkTool 工具性能基准测试辅助函数
(b *testing.B, tool tools.Tool, input map[string]any)
| 460 | |
| 461 | // BenchmarkTool 工具性能基准测试辅助函数 |
| 462 | func BenchmarkTool(b *testing.B, tool tools.Tool, input map[string]any) { |
| 463 | ctx := context.Background() |
| 464 | tc := &tools.ToolContext{ |
| 465 | Signal: ctx, |
| 466 | Sandbox: sandbox.NewMockSandbox(), |
| 467 | } |
| 468 | |
| 469 | b.ResetTimer() |
| 470 | for range b.N { |
| 471 | _, err := tool.Execute(ctx, input, tc) |
| 472 | if err != nil { |
| 473 | b.Fatalf("Tool execution failed: %v", err) |
| 474 | } |
| 475 | } |
| 476 | } |