Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Quickly benchmark how long gobbing and ungobbing takes
package main
import (
func main() {
gobbed := make(map[string]string)
for i := 0; i < 1000000; i++ {
gobbed["123.123.123."+string(i)] = "2015-06-05 15:41:53,262:234567"
f1, _ := os.Create("ips.gob")
//write to file test
t := time.Now()
encoder := gob.NewEncoder(f1)
result1 := time.Since(t)
//write test complete
f2, _ := os.Open("ips.gob")
var ungobbed map[string]string
//read from file test
t = time.Now()
decoder := gob.NewDecoder(f2)
result2 := time.Since(t)
//read test complete
fmt.Printf("time to READ: %f\n", result1.Seconds())
fmt.Printf("time to WRITE: %f\n", result2.Seconds())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.