mirror of
https://github.com/araddon/dateparse.git
synced 2025-01-19 19:26:09 +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) {
|
func BenchmarkParseDateString(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
|
75
parseany.go
75
parseany.go
@ -19,36 +19,36 @@ import (
|
|||||||
// gou.SetColorOutput()
|
// gou.SetColorOutput()
|
||||||
// }
|
// }
|
||||||
|
|
||||||
var days = []string{
|
var knownDays = map[string]struct{}{
|
||||||
"mon",
|
"mon": {},
|
||||||
"tue",
|
"tue": {},
|
||||||
"wed",
|
"wed": {},
|
||||||
"thu",
|
"thu": {},
|
||||||
"fri",
|
"fri": {},
|
||||||
"sat",
|
"sat": {},
|
||||||
"sun",
|
"sun": {},
|
||||||
"monday",
|
"monday": {},
|
||||||
"tuesday",
|
"tuesday": {},
|
||||||
"wednesday",
|
"wednesday": {},
|
||||||
"thursday",
|
"thursday": {},
|
||||||
"friday",
|
"friday": {},
|
||||||
"saturday",
|
"saturday": {},
|
||||||
"sunday",
|
"sunday": {},
|
||||||
}
|
}
|
||||||
|
|
||||||
var months = []string{
|
var knownMonths = map[string]struct{}{
|
||||||
"january",
|
"january": {},
|
||||||
"february",
|
"february": {},
|
||||||
"march",
|
"march": {},
|
||||||
"april",
|
"april": {},
|
||||||
"may",
|
"may": {},
|
||||||
"june",
|
"june": {},
|
||||||
"july",
|
"july": {},
|
||||||
"august",
|
"august": {},
|
||||||
"september",
|
"september": {},
|
||||||
"october",
|
"october": {},
|
||||||
"november",
|
"november": {},
|
||||||
"december",
|
"december": {},
|
||||||
}
|
}
|
||||||
|
|
||||||
type dateState uint8
|
type dateState uint8
|
||||||
@ -3080,21 +3080,10 @@ func (p *parser) parse(originalLoc *time.Location, originalOpts ...ParserOption)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
func isDay(alpha string) bool {
|
func isDay(alpha string) bool {
|
||||||
for _, day := range days {
|
_, ok := knownDays[alpha]
|
||||||
if alpha == day {
|
return ok
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
func isMonthFull(alpha string) bool {
|
func isMonthFull(alpha string) bool {
|
||||||
if len(alpha) > len("september") {
|
_, ok := knownMonths[alpha]
|
||||||
return false
|
return ok
|
||||||
}
|
|
||||||
for _, month := range months {
|
|
||||||
if alpha == month {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user