File: expvar_test.go

package info (click to toggle)
golang-github-anacrolix-missinggo 2.1.0-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 872 kB
  • sloc: makefile: 4
file content (30 lines) | stat: -rw-r--r-- 519 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package xprometheus

import (
	"sync"
	"testing"

	"github.com/bradfitz/iter"
	"github.com/prometheus/client_golang/prometheus"
)

func BenchmarkExpvarCollector_Collect(b *testing.B) {
	ec := NewExpvarCollector()
	ch := make(chan prometheus.Metric)
	n := 0
	var wg sync.WaitGroup
	wg.Add(1)
	go func() {
		defer wg.Done()
		for range ch {
			n++
		}
	}()
	b.ReportAllocs()
	for range iter.N(b.N) {
		ec.Collect(ch)
	}
	close(ch)
	wg.Wait()
	b.Logf("collected %d metrics (%f per collect)", n, float64(n)/float64(b.N))
}