File tree Expand file tree Collapse file tree 7 files changed +84
-12
lines changed Expand file tree Collapse file tree 7 files changed +84
-12
lines changed Original file line number Diff line number Diff line change
1
+ /risor
2
+ /tmp *
1
3
.vscode
2
4
node_modules
3
5
Original file line number Diff line number Diff line change 8
8
gotestsum --junitfile /tmp/test-reports/unit-tests.xml \
9
9
-- -coverprofile=coverage.out -covermode=atomic ./... ./cmd/risor/...
10
10
11
- .PHONY : bench
12
- bench :
11
+ .PHONY : pprof
12
+ pprof :
13
13
go build
14
- ./risor -profile cpu.out ./benchmark/main.mon
14
+ ./risor --cpu- profile cpu.out ./examples/scripts/fibonacci.risor
15
15
go tool pprof -http=:8080 ./cpu.out
16
16
17
+ .PHONY : bench
18
+ bench :
19
+ go test -bench=. -benchmem ./bench
20
+
17
21
# https://code.visualstudio.com/api/working-with-extensions/publishing-extension#packaging-extensions
18
22
.PHONY : install-tools
19
23
install-tools :
Original file line number Diff line number Diff line change @@ -206,6 +206,15 @@ is already available which currently only offers syntax highlighting.
206
206
207
207
You can also make use of the [ Risor TextMate grammar] ( ./vscode/syntaxes/risor.grammar.json ) .
208
208
209
+ ## Benchmarking
210
+
211
+ There are two Makefile commands that assist with benchmarking and CPU profiling:
212
+
213
+ ```
214
+ make bench
215
+ make pprof
216
+ ```
217
+
209
218
## Contributing
210
219
211
220
Risor is intended to be a community project. You can lend a hand in various ways:
Original file line number Diff line number Diff line change
1
+ package risor_test
2
+
3
+ import (
4
+ "context"
5
+ "log"
6
+ "testing"
7
+
8
+ "github.com/risor-io/risor/compiler"
9
+ "github.com/risor-io/risor/parser"
10
+ "github.com/risor-io/risor/vm"
11
+ )
12
+
13
+ func BenchmarkRisor_Fibonacci35 (b * testing.B ) {
14
+ script := `
15
+ func fibonacci(n) {
16
+ if n <= 1 {
17
+ return n
18
+ }
19
+ return fibonacci(n-1) + fibonacci(n-2)
20
+ }
21
+ fibonacci(35)
22
+ `
23
+
24
+ ctx := context .Background ()
25
+
26
+ ast , err := parser .Parse (ctx , script )
27
+ if err != nil {
28
+ log .Fatal (err )
29
+ }
30
+
31
+ code , err := compiler .Compile (ast )
32
+ if err != nil {
33
+ log .Fatal (err )
34
+ }
35
+
36
+ b .ResetTimer ()
37
+ for i := 0 ; i < b .N ; i ++ {
38
+ result , err := vm .Run (ctx , code )
39
+ if err != nil {
40
+ b .Fatal (err )
41
+ }
42
+ if result .Interface ().(int64 ) != 9227465 {
43
+ b .Fatalf ("unexpected result: %v" , result )
44
+ }
45
+ }
46
+ }
Original file line number Diff line number Diff line change 5
5
"fmt"
6
6
"os"
7
7
"path/filepath"
8
+ "runtime/pprof"
8
9
"strings"
9
10
"time"
10
11
@@ -132,6 +133,16 @@ var rootCmd = &cobra.Command{
132
133
ctx := context .Background ()
133
134
processGlobalFlags ()
134
135
136
+ if path := viper .GetString ("cpu-profile" ); path != "" {
137
+ f , err := os .Create (path )
138
+ if err != nil {
139
+ fatal (err )
140
+ }
141
+ pprof .StartCPUProfile (f )
142
+ defer pprof .StopCPUProfile ()
143
+ handleSigForProfiler ()
144
+ }
145
+
135
146
// Separate arguments belonging to the Risor CLI from those that are
136
147
// to be passed to the script.
137
148
var scriptArgs []string
Original file line number Diff line number Diff line change @@ -173,13 +173,4 @@ func processGlobalFlags() {
173
173
if viper .GetBool ("no-color" ) {
174
174
color .NoColor = true
175
175
}
176
- if path := viper .GetString ("cpu-profile" ); path != "" {
177
- f , err := os .Create (path )
178
- if err != nil {
179
- fatal (err )
180
- }
181
- pprof .StartCPUProfile (f )
182
- defer pprof .StopCPUProfile ()
183
- handleSigForProfiler ()
184
- }
185
176
}
Original file line number Diff line number Diff line change
1
+
2
+ func fibonacci(n) {
3
+ if n <= 1 {
4
+ return n
5
+ }
6
+ return fibonacci(n-1) + fibonacci(n-2)
7
+ }
8
+
9
+ fibonacci(35)
You can’t perform that action at this time.
0 commit comments