diff options
| author | Andy Pan <panjf2000@gmail.com> | 2022-08-20 19:21:39 +0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2022-08-24 05:40:28 +0000 |
| commit | 1a8dfadbfe26978cba0d6ce57bf437a93f796da6 (patch) | |
| tree | 8b2d011e738502183aafb78acfdae22e0a8df6b9 /src/encoding/json | |
| parent | 75cdd2c75dfa3f8095f9e9304513445d461580d4 (diff) | |
| download | go-1a8dfadbfe26978cba0d6ce57bf437a93f796da6.tar.xz | |
encoding/json: move some misplaced benchmark tests to bench_test.go
Change-Id: I5987eed00ee825421abe62699a06e9b66499f35f
Reviewed-on: https://go-review.googlesource.com/c/go/+/425016
Reviewed-by: Daniel Martà <mvdan@mvdan.cc>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/encoding/json')
| -rw-r--r-- | src/encoding/json/bench_test.go | 31 | ||||
| -rw-r--r-- | src/encoding/json/number_test.go | 15 | ||||
| -rw-r--r-- | src/encoding/json/stream_test.go | 15 |
3 files changed, 31 insertions, 30 deletions
diff --git a/src/encoding/json/bench_test.go b/src/encoding/json/bench_test.go index 133084976b..d3af0dc0ed 100644 --- a/src/encoding/json/bench_test.go +++ b/src/encoding/json/bench_test.go @@ -18,6 +18,7 @@ import ( "io" "os" "reflect" + "regexp" "runtime" "strings" "sync" @@ -508,3 +509,33 @@ func BenchmarkEncodeMarshaler(b *testing.B) { } }) } + +func BenchmarkEncoderEncode(b *testing.B) { + b.ReportAllocs() + type T struct { + X, Y string + } + v := &T{"foo", "bar"} + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + if err := NewEncoder(io.Discard).Encode(v); err != nil { + b.Fatal(err) + } + } + }) +} + +func BenchmarkNumberIsValid(b *testing.B) { + s := "-61657.61667E+61673" + for i := 0; i < b.N; i++ { + isValidNumber(s) + } +} + +func BenchmarkNumberIsValidRegexp(b *testing.B) { + var jsonNumberRegexp = regexp.MustCompile(`^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$`) + s := "-61657.61667E+61673" + for i := 0; i < b.N; i++ { + jsonNumberRegexp.MatchString(s) + } +} diff --git a/src/encoding/json/number_test.go b/src/encoding/json/number_test.go index cc6701814f..c82e6deb83 100644 --- a/src/encoding/json/number_test.go +++ b/src/encoding/json/number_test.go @@ -116,18 +116,3 @@ func TestNumberIsValid(t *testing.T) { } } } - -func BenchmarkNumberIsValid(b *testing.B) { - s := "-61657.61667E+61673" - for i := 0; i < b.N; i++ { - isValidNumber(s) - } -} - -func BenchmarkNumberIsValidRegexp(b *testing.B) { - var jsonNumberRegexp = regexp.MustCompile(`^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$`) - s := "-61657.61667E+61673" - for i := 0; i < b.N; i++ { - jsonNumberRegexp.MatchString(s) - } -} diff --git a/src/encoding/json/stream_test.go b/src/encoding/json/stream_test.go index 1f40c79670..712293de0f 100644 --- a/src/encoding/json/stream_test.go +++ b/src/encoding/json/stream_test.go @@ -347,21 +347,6 @@ func TestBlocking(t *testing.T) { } } -func BenchmarkEncoderEncode(b *testing.B) { - b.ReportAllocs() - type T struct { - X, Y string - } - v := &T{"foo", "bar"} - b.RunParallel(func(pb *testing.PB) { - for pb.Next() { - if err := NewEncoder(io.Discard).Encode(v); err != nil { - b.Fatal(err) - } - } - }) -} - type tokenStreamCase struct { json string expTokens []any |
