Merge pull request #99 from goccy/feature/add-bench

Add some benchmarks for encoder
This commit is contained in:
Masaaki Goshima 2021-01-27 10:58:23 +09:00 committed by GitHub
commit fe1fa3915a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 66 additions and 0 deletions

View File

@ -537,3 +537,69 @@ func Benchmark_Encode_MapInterface_GoJson(b *testing.B) {
}
}
}
func Benchmark_Encode_Interface_SegmentioJson(b *testing.B) {
v := []interface{}{1}
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if _, err := segmentiojson.Marshal(v); err != nil {
b.Fatal(err)
}
}
}
func Benchmark_Encode_Interface_GoJson(b *testing.B) {
v := []interface{}{1}
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if _, err := gojson.Marshal(v); err != nil {
b.Fatal(err)
}
}
}
func Benchmark_Encode_Int_EncodingJson(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if _, err := json.Marshal(1); err != nil {
b.Fatal(err)
}
}
}
func Benchmark_Encode_Int_JsonIter(b *testing.B) {
var json = jsoniter.ConfigCompatibleWithStandardLibrary
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if _, err := json.Marshal(1); err != nil {
b.Fatal(err)
}
}
}
func Benchmark_Encode_Int_Jettison(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if _, err := jettison.Marshal(1); err != nil {
b.Fatal(err)
}
}
}
func Benchmark_Encode_Int_SegmentioJson(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if _, err := segmentiojson.Marshal(1); err != nil {
b.Fatal(err)
}
}
}
func Benchmark_Encode_Int_GoJson(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if _, err := gojson.Marshal(1); err != nil {
b.Fatal(err)
}
}
}