Skip to content
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

Merged
merged 1 commit into from May 17, 2020
Merged

performance improvement for parseDateTime #1098

merged 1 commit into from May 17, 2020

Conversation

chanxuehong
Copy link
Contributor

@chanxuehong chanxuehong commented May 13, 2020

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

  • Code compiles correctly
  • Created tests which fail without the change (if possible)
  • All tests passing
  • Extended the README / documentation, if necessary
  • Added myself / the copyright holder to the AUTHORS file

Copy link
Member

@julienschmidt julienschmidt left a 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) {
Copy link
Member

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.

Copy link
Contributor Author

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) {
Copy link
Member

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

Copy link
Contributor Author

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BenchmarkParseDateTime

Copy link
Contributor Author

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also remove this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@julienschmidt julienschmidt added this to the v1.6.0 milestone May 16, 2020
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>
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@julienschmidt julienschmidt left a 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.

@julienschmidt julienschmidt merged commit 096feaa into go-sql-driver:master May 17, 2020
if loc == time.UTC {
return time.Parse(timeFormat[:len(str)], str)
}
return time.ParseInLocation(timeFormat[:len(str)], str, loc)
Copy link
Contributor

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?

tz70s pushed a commit to tz70s/mysql that referenced this pull request Sep 5, 2020
tz70s pushed a commit to tz70s/mysql that referenced this pull request Sep 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants