-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
performance improvement for parseDateTime #1098
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this pull-request!
Please also indicate who the copyright holder is / make an addition to the AUTHORS file.
utils_test.go
Outdated
@@ -291,3 +293,82 @@ func TestIsolationLevelMapping(t *testing.T) { | |||
t.Fatalf("Expected error to be %q, got %q", expectedErr, err) | |||
} | |||
} | |||
|
|||
func parseDateTimeOld(str string, loc *time.Location) (t time.Time, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was useful for demonstrating the diff, but please remove this now. We do not want to keep the old code around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
utils_test.go
Outdated
return | ||
} | ||
|
||
func Test_parseDateTime(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be named TestParseDateTime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
utils_test.go
Outdated
} | ||
} | ||
|
||
func Benchmark_parseDateTime(b *testing.B) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BenchmarkParseDateTime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
utils_test.go
Outdated
} | ||
} | ||
|
||
func Benchmark_parseDateTimeOld(b *testing.B) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also remove this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
AUTHORS
Outdated
@@ -92,6 +92,7 @@ Xiaobing Jiang <s7v7nislands at gmail.com> | |||
Xiuming Chen <cc at cxm.cc> | |||
Zhenye Xie <xiezhenye at gmail.com> | |||
Zhixin Wen <john.wenzhixin at gmail.com> | |||
Xuehong Chan <chanxuehong at gmail.com> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep the list alphabetically sorted, i.e. add your name after Xiuming's.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
LGTM. Waiting for Travis CI.
if loc == time.UTC { | ||
return time.Parse(timeFormat[:len(str)], str) | ||
} | ||
return time.ParseInLocation(timeFormat[:len(str)], str, loc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chanxuehong Why not use ParseInLocation
in all cases?
Description
Please explain the changes you made here.
for now, if loc is not nil, will call t.Date and t.Clock, this PR saves these costs
Benchmark_parseDateTime
Benchmark_parseDateTime-8 4921956 238 ns/op
Benchmark_parseDateTimeOld
Benchmark_parseDateTimeOld-8 3827149 319 ns/op
Checklist