all repos

clerk @ f3b258b

missing tooling for ledger/hledger

clerk/journal/parser/benchmark_test.go (view raw)

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
improve analyzer, 1 day ago
1
package parser
2
3
import (
4
	"os"
5
	"testing"
6
7
	"olexsmir.xyz/clerk/journal/lexer"
8
	"olexsmir.xyz/clerk/journal/token"
9
)
10
11
func loadTestdata(path string) []byte {
12
	src, err := os.ReadFile(path)
13
	if err != nil {
14
		panic("loadTestdata: " + err.Error())
15
	}
16
	return src
17
}
18
19
var (
20
	basicSrc     = loadTestdata("../../journal/testdata/journals/basic.journal")
21
	personalSrc  = loadTestdata("../../journal/testdata/journals/actual-personal.journal")
22
	sampleSrc    = loadTestdata("../../journal/testdata/journals/actual-sample.journal")
23
	standardSrc  = loadTestdata("../../journal/testdata/journals/actual-ledger-input-standard.dat")
24
	wowSrc       = loadTestdata("../../journal/testdata/journals/actual-ledger-input-wow.dat")
25
	benchmarkSrc = loadTestdata("../../journal/testdata/journals/actual-1ktxns-100accts.journal")
26
)
27
28
func BenchmarkLexer_Basic(b *testing.B) {
29
	for b.Loop() {
30
		l := lexer.New("bench", basicSrc)
31
		for l.Next().Type != token.EOF {
32
		}
33
	}
34
}
35
36
func BenchmarkLexer_Personal(b *testing.B) {
37
	for b.Loop() {
38
		l := lexer.New("bench", personalSrc)
39
		for l.Next().Type != token.EOF {
40
		}
41
	}
42
}
43
44
func BenchmarkLexer_Sample(b *testing.B) {
45
	for b.Loop() {
46
		l := lexer.New("bench", sampleSrc)
47
		for l.Next().Type != token.EOF {
48
		}
49
	}
50
}
51
52
func BenchmarkLexer_Standard(b *testing.B) {
53
	for b.Loop() {
54
		l := lexer.New("bench", standardSrc)
55
		for l.Next().Type != token.EOF {
56
		}
57
	}
58
}
59
60
func BenchmarkLexer_Wow(b *testing.B) {
61
	for b.Loop() {
62
		l := lexer.New("bench", wowSrc)
63
		for l.Next().Type != token.EOF {
64
		}
65
	}
66
}
67
68
func BenchmarkLexer_1kTxns(b *testing.B) {
69
	for b.Loop() {
70
		l := lexer.New("bench", benchmarkSrc)
71
		for l.Next().Type != token.EOF {
72
		}
73
	}
74
}
75
76
func BenchmarkParser_Basic(b *testing.B) {
77
	for b.Loop() {
78
		l := lexer.New("bench", basicSrc)
79
		New(l).ParseJournal()
80
	}
81
}
82
83
func BenchmarkParser_Personal(b *testing.B) {
84
	for b.Loop() {
85
		l := lexer.New("bench", personalSrc)
86
		New(l).ParseJournal()
87
	}
88
}
89
90
func BenchmarkParser_Sample(b *testing.B) {
91
	for b.Loop() {
92
		l := lexer.New("bench", sampleSrc)
93
		New(l).ParseJournal()
94
	}
95
}
96
97
func BenchmarkParser_Standard(b *testing.B) {
98
	for b.Loop() {
99
		l := lexer.New("bench", standardSrc)
100
		New(l).ParseJournal()
101
	}
102
}
103
104
func BenchmarkParser_Wow(b *testing.B) {
105
	for b.Loop() {
106
		l := lexer.New("bench", wowSrc)
107
		New(l).ParseJournal()
108
	}
109
}
110
111
func BenchmarkParser_1kTxns(b *testing.B) {
112
	for b.Loop() {
113
		l := lexer.New("bench", benchmarkSrc)
114
		New(l).ParseJournal()
115
	}
116
}
117
118
func BenchmarkParser_1kTxns_Allocs(b *testing.B) {
119
	b.ReportAllocs()
120
	for b.Loop() {
121
		l := lexer.New("bench", benchmarkSrc)
122
		New(l).ParseJournal()
123
	}
124
}
125
126
func BenchmarkParser_Parallel_1kTxns(b *testing.B) {
127
	b.RunParallel(func(pb *testing.PB) {
128
		for pb.Next() {
129
			l := lexer.New("bench", benchmarkSrc)
130
			New(l).ParseJournal()
131
		}
132
	})
133
}