github.com/TeaOSLab/EdgeNode@v1.3.8/internal/zero/zero_test.go (about) 1 // Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. 2 3 package zero 4 5 import ( 6 "runtime" 7 "testing" 8 ) 9 10 func TestZero_Chan(t *testing.T) { 11 var stat1 = &runtime.MemStats{} 12 runtime.ReadMemStats(stat1) 13 14 var m = make(chan Zero, 2_000_000) 15 for i := 0; i < 1_000_000; i++ { 16 m <- New() 17 } 18 19 var stat2 = &runtime.MemStats{} 20 runtime.ReadMemStats(stat2) 21 t.Log(stat2.HeapInuse, stat1.HeapInuse, stat2.HeapInuse-stat1.HeapInuse, "B") 22 t.Log(len(m)) 23 } 24 25 func TestZero_Map(t *testing.T) { 26 var stat1 = &runtime.MemStats{} 27 runtime.ReadMemStats(stat1) 28 29 var m = map[int]Zero{} 30 for i := 0; i < 1_000_000; i++ { 31 m[i] = New() 32 } 33 34 var stat2 = &runtime.MemStats{} 35 runtime.ReadMemStats(stat2) 36 t.Log((stat2.HeapInuse-stat1.HeapInuse)/1024/1024, "MB") 37 t.Log(len(m)) 38 39 _, ok := m[1024] 40 t.Log(ok) 41 }