]> Cypherpunks repositories - gostls13.git/commitdiff
mime: add benchmarks for TypeByExtension and ExtensionsByType
authorBryan C. Mills <bcmills@google.com>
Tue, 14 Feb 2017 22:06:57 +0000 (17:06 -0500)
committerBryan Mills <bcmills@google.com>
Tue, 14 Feb 2017 23:02:07 +0000 (23:02 +0000)
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>
src/mime/type_test.go

index c6c1491a98791e4dd7a48b59a4ade3c87b9846d4..e7aef9a1968b4defe869a6b30ddb5a80a3d5a7f6 100644 (file)
@@ -148,3 +148,43 @@ func TestLookupMallocs(t *testing.T) {
                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)
+                                       }
+                               }
+                       })
+               })
+       }
+}