Skip to content

Instantly share code, notes, and snippets.

@ta1hia
Created June 9, 2015 23:21
Show Gist options
  • Save ta1hia/979cd0d3e6905f38b34a to your computer and use it in GitHub Desktop.
Save ta1hia/979cd0d3e6905f38b34a to your computer and use it in GitHub Desktop.
Quickly benchmark how long gobbing and ungobbing takes
package main
import (
"encoding/gob"
"fmt"
"os"
"time"
)
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)
encoder.Encode(gobbed)
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)
decoder.Decode(&ungobbed)
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())
f1.Close()
f2.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment