Created
August 21, 2020 15:53
-
-
Save skanehira/7349a7f9e9f57c8e1d146f1763e8aed0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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