-
Notifications
You must be signed in to change notification settings - Fork 6
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
Feat: Let "ReadBody" return more detailed error #35
base: main
Are you sure you want to change the base?
Conversation
zhyee
commented
Oct 12, 2023
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: zhyee The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
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.
@coanor +review PR
7ff777a
to
7770763
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: zhyee The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
if c == v { | ||
return k | ||
} | ||
if category, ok := URLCategoryMap[c]; ok { |
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.
将 array 优化成 map,在基础数据量比较小(~ 10 个左右)的情况下,基本没什么提升。
当基础数据量在 32 个时,map 会比 array 快 30% 左右。参见如下示例:
func BenchmarkMapArray(b *T.B) {
arr := []string{
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"10", "110", "1110",
"20", "120", "1120",
"30", "130", "1130",
"40", "140", "1140",
"50", "150", "1150",
"60", "160", "1160",
"70", "170", "1170",
"80", "180", "1180",
}
farr := func(x string) bool {
for _, ent := range arr {
if ent == x {
return true
}
}
return false
}
dict := map[string]bool{
"1": true,
"2": true,
"3": true,
"4": true,
"5": true,
"6": true,
"7": true,
"8": true,
"10": true, "110": true, "1110": true,
"20": true, "120": true, "1120": true,
"30": true, "130": true, "1130": true,
"40": true, "140": true, "1140": true,
"50": true, "150": true, "1150": true,
"60": true, "160": true, "1160": true,
"70": true, "170": true, "1170": true,
"80": true, "180": true, "1180": true,
}
fdict := func(x string) bool {
_, ok := dict[x]
return ok
}
b.Run(fmt.Sprintf("arr-%d", len(arr)), func(b *T.B) {
for i := 0; i < b.N; i++ {
farr(fmt.Sprintf("%d", i%len(arr)))
}
})
b.Run(fmt.Sprintf("dict-%d", len(dict)), func(b *T.B) {
for i := 0; i < b.N; i++ {
fdict(fmt.Sprintf("%d", i%len(arr)))
}
})
}
结果:
goos: darwin
goarch: arm64
pkg: gitlab.jiagouyun.com/cloudcare-tools/demo/x
BenchmarkMapArray
BenchmarkMapArray/arr-32
BenchmarkMapArray/arr-32-10 17134858 69.84 ns/op 1 B/op 0 allocs/op
BenchmarkMapArray/dict-32
BenchmarkMapArray/dict-32-10 20657643 57.55 ns/op 1 B/op 0 allocs/op
PASS
ok gitlab.jiagouyun.com/cloudcare-tools/demo/x 3.679s