recursive-llm-ts 5.0.0 → 5.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,168 +0,0 @@
1
- package rlm
2
-
3
- import (
4
- "strings"
5
- "testing"
6
- )
7
-
8
- // Benchmark parser performance
9
- func BenchmarkIsFinal(b *testing.B) {
10
- responses := []string{
11
- `FINAL("answer")`,
12
- `FINAL_VAR(result)`,
13
- `x = 1`,
14
- `console.log("test")`,
15
- }
16
- b.ResetTimer()
17
- for i := 0; i < b.N; i++ {
18
- IsFinal(responses[i%len(responses)])
19
- }
20
- }
21
-
22
- func BenchmarkExtractFinal(b *testing.B) {
23
- response := `FINAL("This is a test answer with some content")`
24
- b.ResetTimer()
25
- for i := 0; i < b.N; i++ {
26
- extractFinal(response)
27
- }
28
- }
29
-
30
- func BenchmarkParseResponse(b *testing.B) {
31
- response := `FINAL("Test answer")`
32
- env := map[string]interface{}{
33
- "result": "test",
34
- }
35
- b.ResetTimer()
36
- for i := 0; i < b.N; i++ {
37
- ParseResponse(response, env)
38
- }
39
- }
40
-
41
- // Benchmark REPL performance
42
- func BenchmarkREPLSimpleExecution(b *testing.B) {
43
- repl := NewREPLExecutor()
44
- code := `console.log("Hello World")`
45
- env := map[string]interface{}{}
46
-
47
- b.ResetTimer()
48
- for i := 0; i < b.N; i++ {
49
- _, _ = repl.Execute(code, env)
50
- }
51
- }
52
-
53
- func BenchmarkREPLContextAccess(b *testing.B) {
54
- repl := NewREPLExecutor()
55
- code := `console.log(context.slice(0, 10))`
56
- env := map[string]interface{}{
57
- "context": strings.Repeat("Lorem ipsum dolor sit amet. ", 1000),
58
- }
59
-
60
- b.ResetTimer()
61
- for i := 0; i < b.N; i++ {
62
- _, _ = repl.Execute(code, env)
63
- }
64
- }
65
-
66
- func BenchmarkREPLRegex(b *testing.B) {
67
- repl := NewREPLExecutor()
68
- code := `const matches = re.findall("ERROR", context); console.log(matches.length)`
69
- context := strings.Repeat("INFO ERROR WARNING ", 100)
70
- env := map[string]interface{}{
71
- "context": context,
72
- "re": NewRegexHelper(),
73
- }
74
-
75
- b.ResetTimer()
76
- for i := 0; i < b.N; i++ {
77
- _, _ = repl.Execute(code, env)
78
- }
79
- }
80
-
81
- func BenchmarkREPLJSBootstrap(b *testing.B) {
82
- repl := NewREPLExecutor()
83
- code := `const arr = range(100); const s = sum(arr); console.log(s)`
84
- env := map[string]interface{}{}
85
-
86
- b.ResetTimer()
87
- for i := 0; i < b.N; i++ {
88
- _, _ = repl.Execute(code, env)
89
- }
90
- }
91
-
92
- // Benchmark regex helper
93
- func BenchmarkRegexFindall(b *testing.B) {
94
- re := NewRegexHelper()
95
- text := strings.Repeat("ERROR INFO WARNING ERROR ", 100)
96
-
97
- b.ResetTimer()
98
- for i := 0; i < b.N; i++ {
99
- re["findall"]("ERROR", text)
100
- }
101
- }
102
-
103
- func BenchmarkRegexSearch(b *testing.B) {
104
- re := NewRegexHelper()
105
- text := strings.Repeat("INFO WARNING ", 50) + "ERROR" + strings.Repeat(" INFO WARNING", 50)
106
-
107
- b.ResetTimer()
108
- for i := 0; i < b.N; i++ {
109
- re["search"]("ERROR", text)
110
- }
111
- }
112
-
113
- // Benchmark config parsing
114
- func BenchmarkConfigFromMap(b *testing.B) {
115
- config := map[string]interface{}{
116
- "recursive_model": "gpt-4o-mini",
117
- "api_base": "https://api.openai.com/v1",
118
- "api_key": "sk-test",
119
- "max_depth": 5,
120
- "max_iterations": 30,
121
- "temperature": 0.7,
122
- "extra_param": "value",
123
- }
124
-
125
- b.ResetTimer()
126
- for i := 0; i < b.N; i++ {
127
- ConfigFromMap(config)
128
- }
129
- }
130
-
131
- // Benchmark code extraction
132
- func BenchmarkExtractCode(b *testing.B) {
133
- code := "```javascript\nconsole.log('test')\nconst x = 42\n```"
134
-
135
- b.ResetTimer()
136
- for i := 0; i < b.N; i++ {
137
- extractCode(code)
138
- }
139
- }
140
-
141
- // Memory allocation benchmarks
142
- func BenchmarkREPLMemoryAllocation(b *testing.B) {
143
- repl := NewREPLExecutor()
144
- code := `const arr = []; for (let i = 0; i < 1000; i++) arr.push(i); console.log(arr.length)`
145
- env := map[string]interface{}{}
146
-
147
- b.ReportAllocs()
148
- b.ResetTimer()
149
- for i := 0; i < b.N; i++ {
150
- _, _ = repl.Execute(code, env)
151
- }
152
- }
153
-
154
- func BenchmarkLargeContextAccess(b *testing.B) {
155
- repl := NewREPLExecutor()
156
- // Simulate 100KB context
157
- largeContext := strings.Repeat("Lorem ipsum dolor sit amet, consectetur adipiscing elit. ", 2000)
158
- code := `const first = context.slice(0, 100); const last = context.slice(-100); console.log(first.length + last.length)`
159
- env := map[string]interface{}{
160
- "context": largeContext,
161
- }
162
-
163
- b.ReportAllocs()
164
- b.ResetTimer()
165
- for i := 0; i < b.N; i++ {
166
- _, _ = repl.Execute(code, env)
167
- }
168
- }