chore: improve snakeCasedName performance #1688

Merged
lunny merged 3 commits from performance into master 2020-05-22 02:54:50 +00:00
Owner
No description provided.
lunny added 1 commit 2020-05-21 14:01:03 +00:00
chore: improve snakeCasedName performance
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
cc74a8854a
lunny reviewed 2020-05-21 14:03:29 +00:00
Dismissed
names/mapper.go Outdated
@ -95,0 +98,4 @@
}
func snakeCasedNameNew(name string) string {
newstr := make([]byte, 0)
Author
Owner

How about give a length ? make([]byte, 0, len(name))

How about give a length ? `make([]byte, 0, len(name)) `
Member

Done.

goos: darwin
goarch: amd64
pkg: xorm.io/xorm/names
BenchmarkSnakeCasedName-8         313640              3524 ns/op            2328 B/op          9 allocs/op
BenchmarkSnakeCasedNameNew-8     1901515               617 ns/op             576 B/op          2 allocs/op
PASS
ok      xorm.io/xorm/names      2.976s
Done. ``` goos: darwin goarch: amd64 pkg: xorm.io/xorm/names BenchmarkSnakeCasedName-8 313640 3524 ns/op 2328 B/op 9 allocs/op BenchmarkSnakeCasedNameNew-8 1901515 617 ns/op 576 B/op 2 allocs/op PASS ok xorm.io/xorm/names 2.976s ```
Author
Owner

Sorry, maybe newstr := make([]byte, 0, len(name)+1 is better.

Sorry, maybe `newstr := make([]byte, 0, len(name)+1` is better.
Member

Done

Done
lunny added the
kind
performance
kind
enhancement
labels 2020-05-21 14:04:38 +00:00
Member

The following is bechmark result:

goos: darwin
goarch: amd64
pkg: xorm.io/xorm/names
BenchmarkSnakeCasedName-8         321931              3345 ns/op            2328 B/op          9 allocs/op
BenchmarkSnakeCasedNameNew-8     1577725               735 ns/op             504 B/op          6 allocs/op
PASS
ok      xorm.io/xorm/names      3.062s
The following is bechmark result: ``` goos: darwin goarch: amd64 pkg: xorm.io/xorm/names BenchmarkSnakeCasedName-8 321931 3345 ns/op 2328 B/op 9 allocs/op BenchmarkSnakeCasedNameNew-8 1577725 735 ns/op 504 B/op 6 allocs/op PASS ok xorm.io/xorm/names 3.062s ```
Member

@lunny I will remove the old source code befor merge the PR if review done.

@lunny I will remove the old source code befor merge the PR if review done.
appleboy added 1 commit 2020-05-21 14:16:11 +00:00
chore: udpate
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
fdb6765648
appleboy added 1 commit 2020-05-21 14:30:00 +00:00
chore: update
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
99f0e5e05c
appleboy approved these changes 2020-05-21 14:30:43 +00:00
Dismissed
lunny added this to the 1.1.1 milestone 2020-05-21 14:31:33 +00:00
Member

@lunny Please help to merge the PR.

@lunny Please help to merge the PR.
Member

@lunny Please close the PR. We should cretae new PR and add you as reviewer.

@lunny Please close the PR. We should cretae new PR and add you as reviewer.
lunny merged commit d485101331 into master 2020-05-22 02:53:58 +00:00
lunny deleted branch performance 2020-05-22 02:54:56 +00:00
lunny modified the milestone from 1.1.1 to 1.0.2 2020-06-13 03:15:03 +00:00
Sign in to join this conversation.
No description provided.