Skip to content

Commit d56331f

Browse files
committed
calcMem hotfix
1 parent 052672f commit d56331f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

bench_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ func calcMem(name string, load func()) {
4545
m := new(runtime.MemStats)
4646

4747
// before
48+
// force GC multiple times, since Go is using a generational GC
49+
// TODO: find a better approach
50+
runtime.GC()
51+
runtime.GC()
52+
runtime.GC()
4853
runtime.GC()
4954
runtime.ReadMemStats(m)
5055
before := m.HeapAlloc
@@ -53,6 +58,9 @@ func calcMem(name string, load func()) {
5358

5459
// after
5560
runtime.GC()
61+
runtime.GC()
62+
runtime.GC()
63+
runtime.GC()
5664
runtime.ReadMemStats(m)
5765
after := m.HeapAlloc
5866
println(" "+name+":", after-before, "Bytes")
@@ -220,7 +228,6 @@ func BenchmarkPat_Param(b *testing.B) {
220228
r, _ := http.NewRequest("GET", "/user/gordon", nil)
221229
benchRequest(b, router, r)
222230
}
223-
224231
func BenchmarkPossum_Param(b *testing.B) {
225232
router := loadPossumSingle("GET", "/user/:name", possumHandler)
226233

0 commit comments

Comments
 (0)