(t *testing.T)
| 77 | } |
| 78 | |
| 79 | func 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 | |
| 112 | func BenchmarkCounter_Increase(b *testing.B) { |
| 113 | runtime.GOMAXPROCS(4) |
nothing calls this directly
no test coverage detected