-
Notifications
You must be signed in to change notification settings - Fork 86
/
gen_bench_test.go
61 lines (54 loc) · 1.21 KB
/
gen_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
59
60
61
package ogen_test
import (
"path"
"strings"
"testing"
"github.com/stretchr/testify/require"
"github.com/ogen-go/ogen"
"github.com/ogen-go/ogen/gen"
"github.com/ogen-go/ogen/gen/genfs"
)
func BenchmarkGenerator(b *testing.B) {
files := []string{
"api.github.com.json", // Giant (>90kLOC)
"gotd_bot_api.json", // Medium (>10kLOC)
"tinkoff.json", // Small (>2kLOC)
"manga.json", // Tiny (<1kLOC)
}
for _, file := range files {
file := file
name := strings.TrimSuffix(file, ".json")
b.Run(name, func(b *testing.B) {
a := require.New(b)
data, err := testdata.ReadFile(path.Join("_testdata/examples", file))
a.NoError(err)
spec, err := ogen.Parse(data)
a.NoError(err)
opts := gen.Options{
Parser: gen.ParseOptions{
InferSchemaType: true,
},
Generator: gen.GenerateOptions{
IgnoreNotImplemented: []string{
"all",
},
},
}
dir := b.TempDir()
fs := genfs.FormattedSource{
Root: dir,
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
g, err := gen.NewGenerator(spec, opts)
if err != nil {
b.Fatal(err)
}
if err := g.WriteSource(fs, "api"); err != nil {
b.Fatal(err)
}
}
})
}
}