From 0d2fd5e275b55ec1292e0c727c06da4a7d017973 Mon Sep 17 00:00:00 2001 From: Klondike Dragon Date: Sat, 16 Dec 2023 08:18:54 -0700 Subject: [PATCH] Add broader benchmarks Uses the main test set for a broader stress test. --- bench_test.go | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/bench_test.go b/bench_test.go index 1973308..f979d95 100644 --- a/bench_test.go +++ b/bench_test.go @@ -40,6 +40,63 @@ func BenchmarkParseAny(b *testing.B) { } } +func BenchmarkBigShotgunParse(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + for _, t := range testInputs { + // This is the non dateparse traditional approach + _, _ = parseShotgunStyle(t.in) + } + } +} + +func BenchmarkBigParseAny(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + for _, t := range testInputs { + _, _ = ParseAny(t.in) + } + } +} + +func BenchmarkBigParseIn(b *testing.B) { + b.ReportAllocs() + loc, _ := time.LoadLocation("America/New_York") + for i := 0; i < b.N; i++ { + for _, t := range testInputs { + _, _ = ParseIn(t.in, loc) + } + } +} + +func BenchmarkBigParseRetryAmbiguous(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + for _, t := range testInputs { + _, _ = ParseAny(t.in, RetryAmbiguousDateWithSwap(true)) + } + } +} + +func BenchmarkShotgunParseErrors(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + for _, t := range testParseErrors { + // This is the non dateparse traditional approach + _, _ = parseShotgunStyle(t.in) + } + } +} + +func BenchmarkParseAnyErrors(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + for _, t := range testParseErrors { + _, _ = ParseAny(t.in) + } + } +} + /* func BenchmarkParseDateString(b *testing.B) { b.ReportAllocs()