content_test.go 940 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package message
  2. import (
  3. "fmt"
  4. "strings"
  5. "testing"
  6. )
  7. func makeTestAttachments(n int, contentSize int) []Attachment {
  8. attachments := make([]Attachment, n)
  9. content := []byte(strings.Repeat("x", contentSize))
  10. for i := range n {
  11. attachments[i] = Attachment{
  12. FilePath: fmt.Sprintf("/path/to/file%d.txt", i),
  13. MimeType: "text/plain",
  14. Content: content,
  15. }
  16. }
  17. return attachments
  18. }
  19. func BenchmarkPromptWithTextAttachments(b *testing.B) {
  20. cases := []struct {
  21. name string
  22. numFiles int
  23. contentSize int
  24. }{
  25. {"1file_100bytes", 1, 100},
  26. {"5files_1KB", 5, 1024},
  27. {"10files_10KB", 10, 10 * 1024},
  28. {"20files_50KB", 20, 50 * 1024},
  29. }
  30. for _, tc := range cases {
  31. attachments := makeTestAttachments(tc.numFiles, tc.contentSize)
  32. prompt := "Process these files"
  33. b.Run(tc.name, func(b *testing.B) {
  34. b.ReportAllocs()
  35. for range b.N {
  36. _ = PromptWithTextAttachments(prompt, attachments)
  37. }
  38. })
  39. }
  40. }