protobuf-go/internal/encoding/json/bench_test.go
Kir Kolyshkin bf9455640d all: fix typos
Brought to you by codespell v2.1.0, using the command

	codespell -S .cache,vendor -L ot,ba,fo,unparseable -w

Note that the misspelled "unparseable" comes from the
github.com/protocolbuffers/protobuf, where it is explicitly ignored
(see [1] and some explanation at [2]), so we ignore it here, too.

[1] https://github.com/protocolbuffers/protobuf/pull/7752
[2] https://github.com/protocolbuffers/protobuf/pull/7751#discussion_r460170422

Change-Id: Ie1ca705db4f11df8ec8b22fdc22b6a6ee667ae5b
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/406845
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
2022-05-19 09:32:38 +00:00

64 lines
1.3 KiB
Go

// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package json_test
import (
"testing"
"google.golang.org/protobuf/internal/encoding/json"
)
func BenchmarkFloat(b *testing.B) {
input := []byte(`1.797693134862315708145274237317043567981e+308`)
for i := 0; i < b.N; i++ {
dec := json.NewDecoder(input)
val, err := dec.Read()
if err != nil {
b.Fatal(err)
}
if _, ok := val.Float(64); !ok {
b.Fatal("not a float")
}
}
}
func BenchmarkInt(b *testing.B) {
input := []byte(`922337203.6854775807e+10`)
for i := 0; i < b.N; i++ {
dec := json.NewDecoder(input)
val, err := dec.Read()
if err != nil {
b.Fatal(err)
}
if _, ok := val.Int(64); !ok {
b.Fatal("not an int64")
}
}
}
func BenchmarkString(b *testing.B) {
input := []byte(`"abcdefghijklmnopqrstuvwxyz0123456789\\n\\t"`)
for i := 0; i < b.N; i++ {
dec := json.NewDecoder(input)
val, err := dec.Read()
if err != nil {
b.Fatal(err)
}
_ = val.ParsedString()
}
}
func BenchmarkBool(b *testing.B) {
input := []byte(`true`)
for i := 0; i < b.N; i++ {
dec := json.NewDecoder(input)
val, err := dec.Read()
if err != nil {
b.Fatal(err)
}
_ = val.Bool()
}
}