mirror of
https://github.com/golang/go.git
synced 2025-05-30 11:51:34 +00:00
mime: add benchmarks for TypeByExtension and ExtensionsByType
These are possible use-cases for sync.Map. Updates golang/go#18177 Change-Id: I5e2a3d1249967c37d3f89a41122bf4a90522db11 Reviewed-on: https://go-review.googlesource.com/36964 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
4477fd097f
commit
eebd8f51e8
@ -148,3 +148,43 @@ func TestLookupMallocs(t *testing.T) {
|
|||||||
t.Errorf("allocs = %v; want 0", n)
|
t.Errorf("allocs = %v; want 0", n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkTypeByExtension(b *testing.B) {
|
||||||
|
initMime()
|
||||||
|
b.ResetTimer()
|
||||||
|
|
||||||
|
for _, ext := range []string{
|
||||||
|
".html",
|
||||||
|
".HTML",
|
||||||
|
".unused",
|
||||||
|
} {
|
||||||
|
b.Run(ext, func(b *testing.B) {
|
||||||
|
b.RunParallel(func(pb *testing.PB) {
|
||||||
|
for pb.Next() {
|
||||||
|
TypeByExtension(ext)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkExtensionsByType(b *testing.B) {
|
||||||
|
initMime()
|
||||||
|
b.ResetTimer()
|
||||||
|
|
||||||
|
for _, typ := range []string{
|
||||||
|
"text/html",
|
||||||
|
"text/html; charset=utf-8",
|
||||||
|
"application/octet-stream",
|
||||||
|
} {
|
||||||
|
b.Run(typ, func(b *testing.B) {
|
||||||
|
b.RunParallel(func(pb *testing.PB) {
|
||||||
|
for pb.Next() {
|
||||||
|
if _, err := ExtensionsByType(typ); err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user