jsonBenchmark

package module
v0.0.0-...-b9f6d41 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2022 License: MIT Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Json encoder and decoder benchmark

Test Encode for:

  1. Build-in encoder
  2. https://github.com/mailru/easyjson
  3. https://github.com/json-iterator/go

Test Decode with access to one field for:

  1. Build-in decoder
  2. https://github.com/mailru/easyjson
  3. https://github.com/json-iterator/go
  4. https://github.com/valyala/fastjson (only one field extracted)
  5. https://github.com/tidwall/gjson (only one field extracted)
  6. Parallel https://github.com/valyala/fastjson (only one field extracted)
  7. Parallel https://github.com/tidwall/gjson (only one field extracted)

Test Delete unnecessary field from json document without parsing it into structure:

  1. https://github.com/valyala/fastjson
  2. https://github.com/tidwall/sjson
  3. https://github.com/tidwall/sjson by setting necessary fields in new document (bad idea)
  4. https://github.com/tidwall/gjson by parse to map[interface{}]interface{}, delete fields and Marshal with jsoniter
goos: linux
goarch: amd64
pkg: github.com/satmaelstorm/goJsonBenchmark
cpu: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
BenchmarkStdJsonEncode-8                  420640              2524 ns/op            1112 B/op          6 allocs/op
BenchmarkEasyJsonEncode-8                1000000              1003 ns/op             968 B/op          6 allocs/op
BenchmarkFFJsonEncode-8                   732212              1596 ns/op             528 B/op         16 allocs/op
BenchmarkJsoniterJsonEncode-8            1314940               981.2 ns/op          1112 B/op          6 allocs/op
BenchmarkStdJsonDecode-8                  180108              6610 ns/op             304 B/op         13 allocs/op
BenchmarkEasyJsonDecode-8                 633112              2105 ns/op              42 B/op          8 allocs/op
BenchmarkFFJsonDecode-8                   323800              3143 ns/op             642 B/op         15 allocs/op
BenchmarkJsoniterDecode-8                 292714              4150 ns/op             664 B/op         29 allocs/op
BenchmarkFastJsonDecode-8                1234142               951.5 ns/op             0 B/op          0 allocs/op
BenchmarkGJsonDecode-8                   2475152               465.9 ns/op             3 B/op          1 allocs/op
BenchmarkFastJsonDecodeParallel-8        3799425               338.0 ns/op             0 B/op          0 allocs/op
BenchmarkGJsonDecodeParallel-8           7916830               154.1 ns/op             3 B/op          1 allocs/op
BenchmarkFastJsonDelete-8                 275527              3672 ns/op            3914 B/op          9 allocs/op
BenchmarkSJsonDelete-8                     38605             29378 ns/op           38096 B/op         20 allocs/op
BenchmarkSJsonDeleteBySet-8                15432             78291 ns/op           37584 B/op         40 allocs/op
BenchmarkGJsonDeleteByMap-8                41868             34799 ns/op           20013 B/op         48 allocs/op

IMHO:

  1. If you need to encode or decode into a structure, and you want to avoid code generation, take jsoniter, otherwise, an easyjson one is a great way
  2. If you need a small number of fields from a clear location, you can take gjson
  3. If you need to remove fields from the json without decoding it - fastjson will do the best

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddInfo

type AddInfo struct {
	Id   int    `json:"id"`
	Name string `json:"name"`
	Slug string `json:"slug"`
}

func (AddInfo) MarshalEasyJSON

func (v AddInfo) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (AddInfo) MarshalJSON

func (v AddInfo) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*AddInfo) UnmarshalEasyJSON

func (v *AddInfo) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*AddInfo) UnmarshalJSON

func (v *AddInfo) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type ApiAnswer

type ApiAnswer struct {
	Response Response `json:"response"`
}

func (ApiAnswer) MarshalEasyJSON

func (v ApiAnswer) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (ApiAnswer) MarshalJSON

func (v ApiAnswer) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*ApiAnswer) UnmarshalEasyJSON

func (v *ApiAnswer) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*ApiAnswer) UnmarshalJSON

func (v *ApiAnswer) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type FFAddInfo

type FFAddInfo struct {
	Id   int    `json:"id"`
	Name string `json:"name"`
	Slug string `json:"slug"`
}

func (*FFAddInfo) MarshalJSON

func (j *FFAddInfo) MarshalJSON() ([]byte, error)

MarshalJSON marshal bytes to json - template

func (*FFAddInfo) MarshalJSONBuf

func (j *FFAddInfo) MarshalJSONBuf(buf fflib.EncodingBuffer) error

MarshalJSONBuf marshal buff to json - template

func (*FFAddInfo) UnmarshalJSON

func (j *FFAddInfo) UnmarshalJSON(input []byte) error

UnmarshalJSON umarshall json - template of ffjson

func (*FFAddInfo) UnmarshalJSONFFLexer

func (j *FFAddInfo) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error

UnmarshalJSONFFLexer fast json unmarshall - template ffjson

type FFApiAnswer

type FFApiAnswer struct {
	Response FFResponse `json:"response"`
}

func (*FFApiAnswer) MarshalJSON

func (j *FFApiAnswer) MarshalJSON() ([]byte, error)

MarshalJSON marshal bytes to json - template

func (*FFApiAnswer) MarshalJSONBuf

func (j *FFApiAnswer) MarshalJSONBuf(buf fflib.EncodingBuffer) error

MarshalJSONBuf marshal buff to json - template

func (*FFApiAnswer) UnmarshalJSON

func (j *FFApiAnswer) UnmarshalJSON(input []byte) error

UnmarshalJSON umarshall json - template of ffjson

func (*FFApiAnswer) UnmarshalJSONFFLexer

func (j *FFApiAnswer) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error

UnmarshalJSONFFLexer fast json unmarshall - template ffjson

type FFResponse

type FFResponse struct {
	Rows []FFRowElement `json:"rows"`
}

func (*FFResponse) MarshalJSON

func (j *FFResponse) MarshalJSON() ([]byte, error)

MarshalJSON marshal bytes to json - template

func (*FFResponse) MarshalJSONBuf

func (j *FFResponse) MarshalJSONBuf(buf fflib.EncodingBuffer) error

MarshalJSONBuf marshal buff to json - template

func (*FFResponse) UnmarshalJSON

func (j *FFResponse) UnmarshalJSON(input []byte) error

UnmarshalJSON umarshall json - template of ffjson

func (*FFResponse) UnmarshalJSONFFLexer

func (j *FFResponse) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error

UnmarshalJSONFFLexer fast json unmarshall - template ffjson

type FFRowElement

type FFRowElement struct {
	Id          int       `json:"id"`
	Name        string    `json:"name"`
	Slug        string    `json:"slug"`
	AddInfo     FFAddInfo `json:"add_info"`
	RecordCount int       `json:"record_count"`
}

func (*FFRowElement) MarshalJSON

func (j *FFRowElement) MarshalJSON() ([]byte, error)

MarshalJSON marshal bytes to json - template

func (*FFRowElement) MarshalJSONBuf

func (j *FFRowElement) MarshalJSONBuf(buf fflib.EncodingBuffer) error

MarshalJSONBuf marshal buff to json - template

func (*FFRowElement) UnmarshalJSON

func (j *FFRowElement) UnmarshalJSON(input []byte) error

UnmarshalJSON umarshall json - template of ffjson

func (*FFRowElement) UnmarshalJSONFFLexer

func (j *FFRowElement) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error

UnmarshalJSONFFLexer fast json unmarshall - template ffjson

type Response

type Response struct {
	Rows []RowElement `json:"rows"`
}

func (Response) MarshalEasyJSON

func (v Response) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Response) MarshalJSON

func (v Response) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Response) UnmarshalEasyJSON

func (v *Response) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Response) UnmarshalJSON

func (v *Response) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type RowElement

type RowElement struct {
	Id          int     `json:"id"`
	Name        string  `json:"name"`
	Slug        string  `json:"slug"`
	AddInfo     AddInfo `json:"add_info"`
	RecordCount int     `json:"record_count"`
}

func (RowElement) MarshalEasyJSON

func (v RowElement) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (RowElement) MarshalJSON

func (v RowElement) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*RowElement) UnmarshalEasyJSON

func (v *RowElement) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*RowElement) UnmarshalJSON

func (v *RowElement) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL