bench_test.go.1 874 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package mllama
  2. import (
  3. "errors"
  4. "os"
  5. "path/filepath"
  6. "testing"
  7. "github.com/ollama/ollama/model"
  8. )
  9. func BenchmarkProcessText(b *testing.B) {
  10. ours, err := model.New(filepath.Join("testdata", "model.bin"))
  11. if errors.Is(err, os.ErrNotExist) {
  12. b.Skip("no model.bin")
  13. } else if err != nil {
  14. b.Fatal(err)
  15. }
  16. var ids []int32
  17. b.Run("encode", func(b *testing.B) {
  18. txt, err := os.ReadFile(filepath.Join("..", "testdata", "war-and-peace.txt"))
  19. if err != nil {
  20. b.Fatal(err)
  21. }
  22. for i := 0; i < b.N; i++ {
  23. b.StopTimer()
  24. b.StartTimer()
  25. ids, err = ours.(model.TextProcessor).Encode(string(txt))
  26. if err != nil {
  27. b.Fatal(err)
  28. }
  29. }
  30. })
  31. b.Run("decode", func(b *testing.B) {
  32. for i := 0; i < b.N; i++ {
  33. b.StopTimer()
  34. b.StartTimer()
  35. _, err = ours.(model.TextProcessor).Decode(ids)
  36. if err != nil {
  37. b.Fatal(err)
  38. }
  39. }
  40. })
  41. }