From 3288b015fc182255a8512df844f4354c95362627 Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Thu, 28 Sep 2017 17:58:13 -0500 Subject: [PATCH] Add basic diagnostics benchmark --- diagnostics/diagnostics_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/diagnostics/diagnostics_test.go b/diagnostics/diagnostics_test.go index 85cdc56d6..1a811df9c 100644 --- a/diagnostics/diagnostics_test.go +++ b/diagnostics/diagnostics_test.go @@ -6,6 +6,7 @@ import ( "net/http" "net/http/httptest" "reflect" + "runtime" "strings" "testing" "time" @@ -141,3 +142,26 @@ func compareJSON(a, b []byte) (bool, error) { } return reflect.DeepEqual(j1, j2), nil } + +func BenchmarkDiagnostics(b *testing.B) { + // Mock server. + server := httptest.NewServer(nil) + defer server.Close() + + // Create a new client. + d := diagnostics.New(server.URL) + d.SetLogger(ioutil.Discard) + defer d.Close() + + prev := runtime.GOMAXPROCS(4) + defer runtime.GOMAXPROCS(prev) + + b.ResetTimer() + + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + d.Count("cc", 1, 1.0) + d.Gauge("gg", 10, 1.0) + } + }) +}