forked from grafana/k6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench_test.go
58 lines (52 loc) · 1.17 KB
/
bench_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"context"
"testing"
"github.com/loadimpact/k6/lib"
"github.com/spf13/afero"
)
func BenchmarkJSRunners(b *testing.B) {
scripts := map[string]string{
"Empty": `export default function() {}`,
"HTTP": `import http from "k6/http"; export default function() { http.get("http://localhost:8080/"); }`,
}
for name, script := range scripts {
b.Run(name, func(b *testing.B) {
for _, t := range []string{"js", "js2"} {
b.Run(t, func(b *testing.B) {
r, err := makeRunner(t, &lib.SourceData{
Filename: "/script.js",
Data: []byte(script),
}, afero.NewMemMapFs())
if err != nil {
b.Error(err)
return
}
b.Run("Spawn", func(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := r.NewVU()
if err != nil {
b.Error(err)
return
}
}
})
b.Run("Run", func(b *testing.B) {
vu, err := r.NewVU()
if err != nil {
b.Error(err)
return
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := vu.RunOnce(context.Background())
if err != nil {
b.Error(err)
}
}
})
})
}
})
}
}