前端
for-loop 与 json.Unmarshal 性能分析概要
Posts on 煎é±0 次浏览
在项目中,常常会遇到循环交换赋值的数据处理场景,尤其是 RPC,数据交互格式要转为 Protobuf,赋值是无法避免的。一般会有如下几种做法: for for range json.Marshal/Unmarshal 这时候又面临 “选择困难症”,用哪个好?又想代码量少,又担心性能有没有影响啊… 为了弄清楚这个疑惑,接下来将分别编写三种使用场景。来简单看看它们的性能情况,看看谁更 “好” 功能代码 ... type Person struct { Name string `json:"name"` Age int `json:"age"` Avatar string `json:"avatar"` Type string `json:"type"` } type AgainPerson struct { Name string `json:"name"` Age int `json:"age"` Avatar string `json:"avatar"` Type string `json:"type"` } const MAX = 10000 func InitPerson() []Person { var persons []Person for i := 0; i < MAX; i++ { persons = append(persons, Person{ Name: "EDDYCJY", Age: i, Avatar: "https://github.
原文:https://eddycjy.com/posts/go/talk/2019-02-17-for-loop-json-unmarshal/



