doujia9833 2015-01-30 17:15
浏览 444
已采纳

GoLang-编码/json.Marshal或fmt.sprintf?

Which would be faster?

data := fmt.Sprintf("{\"TEST\":3, \"ID\":\"%s\"}", Id)

OR json marshalling a struct like that?

  • 写回答

2条回答 默认 最新

  • dongyuluan7494 2015-01-31 03:39
    关注

    Highly depends on what you're trying to do, you should benchmark it and see.

    However for your very specific example, the fastest way is just use basic string concat like :

    data := `{"TEST":3, "ID":"` + Id + `"}`
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?