mirror of
https://github.com/araddon/dateparse.git
synced 2025-01-19 11:16:12 +08:00
Optimize checks for day of week and full month
Reduces CPU usage on large benchmarks by ~2%-3% and prepares for future with international month names in future.
This commit is contained in:
parent
fbf07cc274
commit
a45d593447
@ -137,6 +137,13 @@ func BenchmarkParseAmbiguous(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkParseWeekdayAndFullMonth(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
MustParse("Monday 02 December 2006 03:04:05 PM UTC")
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func BenchmarkParseDateString(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
|
75
parseany.go
75
parseany.go
@ -19,36 +19,36 @@ import (
|
||||
// gou.SetColorOutput()
|
||||
// }
|
||||
|
||||
var days = []string{
|
||||
"mon",
|
||||
"tue",
|
||||
"wed",
|
||||
"thu",
|
||||
"fri",
|
||||
"sat",
|
||||
"sun",
|
||||
"monday",
|
||||
"tuesday",
|
||||
"wednesday",
|
||||
"thursday",
|
||||
"friday",
|
||||
"saturday",
|
||||
"sunday",
|
||||
var knownDays = map[string]struct{}{
|
||||
"mon": {},
|
||||
"tue": {},
|
||||
"wed": {},
|
||||
"thu": {},
|
||||
"fri": {},
|
||||
"sat": {},
|
||||
"sun": {},
|
||||
"monday": {},
|
||||
"tuesday": {},
|
||||
"wednesday": {},
|
||||
"thursday": {},
|
||||
"friday": {},
|
||||
"saturday": {},
|
||||
"sunday": {},
|
||||
}
|
||||
|
||||
var months = []string{
|
||||
"january",
|
||||
"february",
|
||||
"march",
|
||||
"april",
|
||||
"may",
|
||||
"june",
|
||||
"july",
|
||||
"august",
|
||||
"september",
|
||||
"october",
|
||||
"november",
|
||||
"december",
|
||||
var knownMonths = map[string]struct{}{
|
||||
"january": {},
|
||||
"february": {},
|
||||
"march": {},
|
||||
"april": {},
|
||||
"may": {},
|
||||
"june": {},
|
||||
"july": {},
|
||||
"august": {},
|
||||
"september": {},
|
||||
"october": {},
|
||||
"november": {},
|
||||
"december": {},
|
||||
}
|
||||
|
||||
type dateState uint8
|
||||
@ -3080,21 +3080,10 @@ func (p *parser) parse(originalLoc *time.Location, originalOpts ...ParserOption)
|
||||
}
|
||||
}
|
||||
func isDay(alpha string) bool {
|
||||
for _, day := range days {
|
||||
if alpha == day {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
_, ok := knownDays[alpha]
|
||||
return ok
|
||||
}
|
||||
func isMonthFull(alpha string) bool {
|
||||
if len(alpha) > len("september") {
|
||||
return false
|
||||
}
|
||||
for _, month := range months {
|
||||
if alpha == month {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
_, ok := knownMonths[alpha]
|
||||
return ok
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user