Commit eebd8f51 authored by Bryan C. Mills's avatar Bryan C. Mills Committed by Bryan Mills

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/36964Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 4477fd09
...@@ -148,3 +148,43 @@ func TestLookupMallocs(t *testing.T) { ...@@ -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)
}
}
})
})
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment