1
// Copyright 2011 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
5
// This benchmark tests JSON encoding and decoding performance.
20
jsonbytes = makeJsonBytes()
21
jsondata = makeJsonData()
24
func makeJsonBytes() []byte {
26
r = bytes.NewReader(bytes.Replace(jsonbz2_base64, []byte{'\n'}, nil, -1))
27
r = base64.NewDecoder(base64.StdEncoding, r)
28
r = bzip2.NewReader(r)
29
b, err := ioutil.ReadAll(r)
36
func makeJsonData() JSONResponse {
38
if err := json.Unmarshal(jsonbytes, &v); err != nil {
44
type JSONResponse struct {
45
Tree *JSONNode `json:"tree"`
46
Username string `json:"username"`
49
type JSONNode struct {
50
Name string `json:"name"`
51
Kids []*JSONNode `json:"kids"`
52
CLWeight float64 `json:"cl_weight"`
53
Touches int `json:"touches"`
54
MinT int64 `json:"min_t"`
55
MaxT int64 `json:"max_t"`
56
MeanT int64 `json:"mean_t"`
61
if err := json.Unmarshal(jsonbytes, &r); err != nil {
68
buf, err := json.Marshal(&jsondata)
75
func BenchmarkJSONEncode(b *testing.B) {
76
b.SetBytes(int64(len(jsonbytes)))
77
for i := 0; i < b.N; i++ {
82
func BenchmarkJSONDecode(b *testing.B) {
83
b.SetBytes(int64(len(jsonbytes)))
84
for i := 0; i < b.N; i++ {