-
Notifications
You must be signed in to change notification settings - Fork 73
/
benchmark_test.go
43 lines (33 loc) · 731 Bytes
/
benchmark_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package tiktoken
import (
"fmt"
"os"
"strings"
"testing"
)
const TEST_FILE = "test/test.txt"
func ReadTestFile() ([]byte, error) {
// open and read TEST_FILE
return os.ReadFile(TEST_FILE)
}
func BenchmarkEncoding(b *testing.B) {
fileContent, err := ReadTestFile()
if err != nil {
panic(err)
}
tkm, err := EncodingForModel("gpt-4o")
if err != nil {
panic(err)
}
text := string(fileContent)
for ordersOfMagnitude := 0; ordersOfMagnitude < 4; ordersOfMagnitude++ {
// do actual encoding
fmt.Printf("Encoding %d bytes\n", len(text))
tkm.Encode(text, nil, nil)
stringBuilder := strings.Builder{}
for i := 0; i < 10; i++ {
stringBuilder.WriteString(text)
}
text = stringBuilder.String()
}
}