chore: improve snakeCasedName performance #1688

Merged
lunny merged 3 commits from performance into master 2 years ago
lunny commented 2 years ago
Owner
There is no content yet.
lunny added 1 commit 2 years ago
cc74a8854a chore: improve snakeCasedName performance
lunny reviewed 2 years ago
Dismissed
names/mapper.go Outdated
}
func snakeCasedNameNew(name string) string {
newstr := make([]byte, 0)
lunny commented 2 years ago
Poster
Owner

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

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

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 ```
lunny commented 2 years ago
Poster
Owner

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

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

Done

Done
lunny added the
kind/performance
kind/enhancement
labels 2 years ago
Collaborator

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 ```
Collaborator

@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 2 years ago
fdb6765648 chore: udpate
appleboy added 1 commit 2 years ago
99f0e5e05c chore: update
appleboy approved these changes 2 years ago
Dismissed
lunny added this to the 1.1.1 milestone 2 years ago
Collaborator

@lunny Please help to merge the PR.

@lunny Please help to merge the PR.
Collaborator

@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 2 years ago
lunny deleted branch performance 2 years ago
lunny modified the milestone from 1.1.1 to 1.0.2 2 years ago
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
The pull request has been merged as d485101331.
Sign in to join this conversation.
Loading…
There is no content yet.