clerk/internal/analyzer/benchmark_test.go (view raw)
| 1 | package analyzer |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "olexsmir.xyz/clerk/journal" |
| 7 | ) |
| 8 | |
| 9 | func BenchmarkBuild_BasicJournal(b *testing.B) { |
| 10 | files := loadJournal("../../journal/testdata/journals/basic.journal") |
| 11 | b.ResetTimer() |
| 12 | for b.Loop() { |
| 13 | Build(files) |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | func BenchmarkBuild_1kTxns(b *testing.B) { |
| 18 | files := loadJournal("../../journal/testdata/journals/actual-1ktxns-100accts.journal") |
| 19 | b.ResetTimer() |
| 20 | for b.Loop() { |
| 21 | Build(files) |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | func BenchmarkBuild_Standard(b *testing.B) { |
| 26 | files := loadJournal("../../journal/testdata/journals/actual-ledger-input-standard.dat") |
| 27 | b.ResetTimer() |
| 28 | for b.Loop() { |
| 29 | Build(files) |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | func BenchmarkBuild_Wow(b *testing.B) { |
| 34 | files := loadJournal("../../journal/testdata/journals/actual-ledger-input-wow.dat") |
| 35 | b.ResetTimer() |
| 36 | for b.Loop() { |
| 37 | Build(files) |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | func BenchmarkBuild_1kTxns_Allocs(b *testing.B) { |
| 42 | files := loadJournal("../../journal/testdata/journals/actual-1ktxns-100accts.journal") |
| 43 | b.ResetTimer() |
| 44 | b.ReportAllocs() |
| 45 | for b.Loop() { |
| 46 | Build(files) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | func BenchmarkBuild_Parallel_1kTxns(b *testing.B) { |
| 51 | files := loadJournal("../../journal/testdata/journals/actual-1ktxns-100accts.journal") |
| 52 | b.RunParallel(func(pb *testing.PB) { |
| 53 | for pb.Next() { |
| 54 | Build(files) |
| 55 | } |
| 56 | }) |
| 57 | } |
| 58 | |
| 59 | func BenchmarkPrefixLookup_1kTxns(b *testing.B) { |
| 60 | a := Build(loadJournal("../../journal/testdata/journals/actual-1ktxns-100accts.journal")) |
| 61 | prefixes := make([]string, 0, len(a.AccountsByPrefix)) |
| 62 | for p := range a.AccountsByPrefix { |
| 63 | prefixes = append(prefixes, p) |
| 64 | } |
| 65 | b.ResetTimer() |
| 66 | for b.Loop() { |
| 67 | for _, p := range prefixes { |
| 68 | _ = a.AccountsByPrefix[p] |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | func BenchmarkAccountIteration_1kTxns(b *testing.B) { |
| 74 | a := Build(loadJournal("../../journal/testdata/journals/actual-1ktxns-100accts.journal")) |
| 75 | names := a.AccountNames |
| 76 | b.ResetTimer() |
| 77 | for b.Loop() { |
| 78 | for _, name := range names { |
| 79 | _ = a.Accounts[name].UsedCount |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | func loadJournal(path string) []*journal.ParsedFile { |
| 85 | ldr := journal.NewLoader() |
| 86 | if _, err := ldr.Load(path); err != nil { |
| 87 | panic("loadJournal: " + err.Error()) |
| 88 | } |
| 89 | return ldr.Ordered() |
| 90 | } |