내 프로젝트는 배열을 반환하는 요구 사항 API 내가 fasthttp
같은 lib 디렉토리를 사용하는 것을 시도했다느린 JSON 마샬링과 비 정렬 화
(약 500 요소 구조체), easyjson
, rapidjson
(cgo
콜)을 가지고 있지만, 결과는 아니다 충분하다.
너희들에게 더 좋은 추천이 있니? 여기
내 코드입니다 :type Line struct {
Time string `json:"time" bson:"time"`
Open float64 `json:"open" bson:"open"`
Close float64 `json:"close" bson:"close"`
High float64 `json:"high" bson:"high"`
Low float64 `json:"low" bson:"low"`
Volume float64 `json:"volume" bson:"volume"`
Amount float64 `json:"amount" bson:"amount"`
}
type MultiLines struct {
AllLines []Line `json:"lines"`
}
시험 코드 :
func BenchmarkJson500(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := json.Marshal(&sliceData)
if err != nil {
panic(err)
}
}
}
func BenchmarkUnmarshalJson500(b *testing.B) {
lines := make([]Line, 500)
for i := 0; i < b.N; i++ {
err := json.Unmarshal(sliceJson, &MultiLines{lines})
if err != nil {
panic(err)
}
}
}
func BenchmarkEasyJson500(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := sliceData.MarshalJSON()
if err != nil {
panic(err)
}
}
}
func BenchmarkEasyUnmarshalJson500(b *testing.B) {
for i := 0; i < b.N; i++ {
slice := MultiLines{}
err := slice.UnmarshalJSON(sliceJson)
if err != nil {
panic(err)
}
}
}
그리고 벤치 마크 테스트 결과 : EasyJson가 UnmarshalJSON/MarshalJSON를 다시 작성하기 때문에
BenchmarkUnmarshalJson500-4 500 2821450 ns/op
BenchmarkJson500-4 500 2151984 ns/op
, 그래서 난과 테스트 다른 시간에 생성 된 코드.
BenchmarkEasyJson500-4 1000 1434724 ns/op
BenchmarkEasyUnmarshalJson500-4 1000 1276298 ns/op
어쨌든 ffjson은 easyjson과 매우 유사합니다.
단, cgo 호출 비용이 많이 들기 때문에 rapidjson이 느립니다. – Keto
개선하려는 코드가 없어도 비슷한 질문을 할 수 있습니다. [JSON 디코딩이 매우 느립니다. 무엇이 더 좋은 방법이 될 것이라고?] (http://stackoverflow.com/questions/29282231/go-json-decoding-is-very-slow-what-would-be-a-better-way-to- 해); 및 [JSON 구문 분석 속도 향상] (http://stackoverflow.com/questions/33222075/speeding-up-json-parsing-in-go) – icza
질문에 내 코드를 추가했습니다. 도움을 요청합니다. 다시. – Keto