Skip to content

Instantly share code, notes, and snippets.

@kylebrandt
Created June 26, 2020 14:29
Show Gist options
  • Save kylebrandt/f4338476c502e34fc40755e443dbee74 to your computer and use it in GitHub Desktop.
Save kylebrandt/f4338476c502e34fc40755e443dbee74 to your computer and use it in GitHub Desktop.
random_insights_bench
benchcmp <(/usr/local/go/bin/go test -benchmem -run=^$ github.com/grafana/grafana/pkg/tsdb/azuremonitor -bench '^(BenchmarkOldInsights)$' -v | sed 's/BenchmarkOldInsights/BenchmarkInsightsMetricsResultToFrame/g') <(/usr/local/go/bin/go test -benchmem -run=^$ github.com/grafana/grafana/pkg/tsdb/azuremonitor -bench '^(BenchmarkInsightsMetricsResultToFrame)$' -v)
benchcmp <(/usr/local/go/bin/go test -benchmem -run=^$ github.com/grafana/grafana/pkg/tsdb/azuremonitor -bench '^(BenchmarkOldInsights)$' -v | sed 's/BenchmarkOldInsights/BenchmarkInsightsMetricsResultToFrame/g') <(/usr/local/go/bin/go test -benchmem -run=^$ github.com/grafana/grafana/pkg/tsdb/azuremonitor -bench '^(BenchmarkInsightsMetricsResultToFrame)$' -v)
benchmark old ns/op new ns/op delta
BenchmarkInsightsMetricsResultToFrame-8 11016198 4370087 -60.33%
benchmark old allocs new allocs delta
BenchmarkInsightsMetricsResultToFrame-8 105147 55087 -47.61%
benchmark old bytes new bytes delta
BenchmarkInsightsMetricsResultToFrame-8 7648039 2395678 -68.68%
curl "https://api.applicationinsights.io/v1/apps/DEMO_APP/metrics/traces/count?timespan=PT12H&interval=PT1M&aggregation=sum&segment=client%2FcountryOrRegion,client%2Fcity" -H "x-api-key: DEMO_KEY" > ~/tmp/bigger.json
func BenchmarkInsightsMetricsResultToFrame(b *testing.B) {
res, err := loadInsightsMetricsResponse("applicationinsights/bigger.json")
require.NoError(b, err)
for n := 0; n < b.N; n++ {
_, err = InsightsMetricsResultToFrame(res, "traces/count", "sum", []string{"client/countryOrRegion", "client/city"})
require.NoError(b, err)
}
}
func BenchmarkOldInsights(b *testing.B) {
data, err := ioutil.ReadFile("testdata/applicationinsights/bigger.json")
require.NoError(b, err)
query := &ApplicationInsightsQuery{
IsRaw: false,
}
datasource := &ApplicationInsightsDatasource{}
require.NoError(b, err)
for n := 0; n < b.N; n++ {
_, err := datasource.parseTimeSeriesFromMetrics(data, query)
require.NoError(b, err)
}
}
@kylebrandt
Copy link
Author

Actually not valid since parseTimeSeriesFrom Metrics loads the JSON, changing the bench so that is done once before the function actually means the newer one slower:

benchmark                                   old ns/op     new ns/op     delta
BenchmarkInsightsMetricsResultToFrame-8     2976102       4162126       +39.85%

benchmark                                   old allocs     new allocs     delta
BenchmarkInsightsMetricsResultToFrame-8     19106          54948          +187.60%

benchmark                                   old bytes     new bytes     delta
BenchmarkInsightsMetricsResultToFrame-8     914358        2386178       +160.97%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment