Skip to content

Instantly share code, notes, and snippets.

@skanehira
Created August 21, 2020 15:53
Show Gist options
  • Save skanehira/7349a7f9e9f57c8e1d146f1763e8aed0 to your computer and use it in GitHub Desktop.
Save skanehira/7349a7f9e9f57c8e1d146f1763e8aed0 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"io/ioutil"
"log"
"os"
"testing"
)
func BenchmarkDecode(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
f, err := os.Open("a.json")
if err != nil {
log.Fatal(err)
}
var m interface{}
d := json.NewDecoder(f)
if err := d.Decode(&m); err != nil {
log.Fatal(err)
}
f.Close()
}
}
func BenchmarkUnmarshal(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
c, err := ioutil.ReadFile("a.json")
if err != nil {
log.Fatal(err)
}
var m interface{}
if err := json.Unmarshal(c, &m); err != nil {
log.Fatal(err)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment