Further optimize ambiguous parsing

Optimize the common and special case where mm and dd are the same length, just swap in place. Avoids having to reparse the entire string.

For this case, it's about 30% faster and reduces allocations by about 15%.

This format is especially common, hence the reason to optimize for this case.

Also fix the case for ambiguous date/time in the mm:dd:yyyy format.
This commit is contained in:
Klondike Dragon
2023-12-16 13:52:00 -07:00
parent ed5310d0c1
commit 23f8fa1af0
3 changed files with 100 additions and 22 deletions

View File

@@ -97,6 +97,13 @@ func BenchmarkParseAnyErrors(b *testing.B) {
}
}
func BenchmarkParseAmbiguous(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
MustParse("13/02/2014 04:08:09 +0000 UTC", RetryAmbiguousDateWithSwap(true))
}
}
/*
func BenchmarkParseDateString(b *testing.B) {
b.ReportAllocs()