Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "runtime"
- "golang.org/x/text/language"
- "golang.org/x/text/message"
- )
- var p = message.NewPrinter(language.English)
- func profile(f func() string) {
- var mem runtime.MemStats
- runtime.GC()
- runtime.ReadMemStats(&mem)
- before := mem.Alloc
- title := f()
- runtime.ReadMemStats(&mem)
- after := mem.Alloc
- p.Printf("%s:%d bytes\n", title, after-before)
- }
- func main() {
- var i, j int32
- numUsers := int32(100000)
- profile(func() string {
- v := map[int32]int32{}
- for i = 0; i < numUsers; i++ {
- v[i] = i
- }
- return fmt.Sprintf("%T", v)
- })
- profile(func() string {
- v := map[uint16]uint16{}
- for i = 0; i < numUsers; i++ {
- v[uint16(i)] = uint16(i)
- }
- return fmt.Sprintf("%T", v)
- })
- numUsers = int32(10000)
- max := int32(5000)
- profile(func() string {
- v := map[int32]map[int32]float32{}
- for i = 0; i < numUsers; i++ {
- v[i] = map[int32]float32{}
- for j = 0; j < max; j++ {
- v[i][j] = 0.0
- }
- }
- return fmt.Sprintf("%T", v)
- })
- profile(func() string {
- v := map[uint16]map[uint16]uint8{}
- for i = 0; i < numUsers; i++ {
- v[uint16(i)] = map[uint16]uint8{}
- for j = 0; j < max; j++ {
- // Quantization
- v[uint16(i)][uint16(j)] = uint8(0.0 * 255)
- }
- }
- return fmt.Sprintf("%T", v)
- })
- }
Add Comment
Please, Sign In to add comment