MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / TestCounterMemory

Function TestCounterMemory

internal/utils/counters/counter_test.go:79–110  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

77}
78
79func TestCounterMemory(t *testing.T) {
80 var stat = &runtime.MemStats{}
81 runtime.ReadMemStats(stat)
82
83 var counter = counters.NewCounter[uint32]()
84 for i := 0; i < 1_000_000; i++ {
85 counter.Increase(uint64(i), rands.Int(10, 300))
86 }
87
88 runtime.GC()
89 runtime.GC()
90 debug.FreeOSMemory()
91
92 var stat1 = &runtime.MemStats{}
93 runtime.ReadMemStats(stat1)
94 t.Log((stat1.HeapInuse-stat.HeapInuse)/(1<<20), "MB")
95
96 t.Log(counter.TotalItems())
97
98 var gcPause = func() {
99 var before = time.Now()
100 runtime.GC()
101 var costSeconds = time.Since(before).Seconds()
102 var stats = &debug.GCStats{}
103 debug.ReadGCStats(stats)
104 t.Log("GC pause:", stats.Pause[0].Seconds()*1000, "ms", "cost:", costSeconds*1000, "ms")
105 }
106
107 gcPause()
108
109 _ = counter.TotalItems()
110}
111
112func BenchmarkCounter_Increase(b *testing.B) {
113 runtime.GOMAXPROCS(4)

Callers

nothing calls this directly

Calls 4

LogMethod · 0.80
TotalItemsMethod · 0.80
GCMethod · 0.65
IncreaseMethod · 0.45

Tested by

no test coverage detected