package hashmap import ( "fmt" "runtime" "testing" "474420502.top/eson/structure/compare" ) func TestCount(t *testing.T) { hm := New(HashInt, compare.Int) for i := 0; i < 1000; i++ { hm.Put(i, i) } } func PrintMemUsage() { var m runtime.MemStats runtime.ReadMemStats(&m) // For info on each, see: https://golang.org/pkg/runtime/#MemStats fmt.Printf("Alloc = %v MiB", bToMb(m.Alloc)) fmt.Printf("\tTotalAlloc = %v MiB", bToMb(m.TotalAlloc)) fmt.Printf("\tSys = %v MiB", bToMb(m.Sys)) fmt.Printf("\tNumGC = %v\n", m.NumGC) } func bToMb(b uint64) uint64 { return b / 1024 / 1024 } func BenchmarkCount(b *testing.B) { hm := New(HashInt, compare.Int) b.N = 100000 for i := 0; i < b.N; i++ { hm.Put(i, i) } b.Log(len(hm.table), hm.size) PrintMemUsage() } func BenchmarkGoCount(b *testing.B) { m := make(map[int]int) b.N = 100000 for i := 0; i < b.N; i++ { m[i] = i } b.Log(len(m)) PrintMemUsage() }