This commit is contained in:
Lucien Coffe
2023-05-26 09:43:36 +02:00
commit 0e5dd520cb
3 changed files with 77 additions and 0 deletions

39
cmd/estimate/main.go Normal file
View File

@@ -0,0 +1,39 @@
package main
import (
"fmt"
"math/rand"
"os"
"strconv"
"git.intruders.space/bot/mapsize"
)
func main() {
if len(os.Args) < 2 {
panic("need argument")
}
n, err := strconv.Atoi(os.Args[1])
if err != nil {
panic("bad argument")
}
m := make(map[string]string)
ms := mapsize.New()
for i := 0; i < n*1_000_000; i++ {
k := strconv.FormatUint(rand.Uint64(), 10)
v := "abc"
m[k] = v
ms.Add(len(k), len(v))
}
fmt.Println("do you want an estimate? (y/y)")
var c byte
fmt.Scan(&c)
fmt.Printf("\nestimate: %d kB\n", ms.Size()/1024)
}