Closed bethebest0622 closed 2 months ago
in situation you described, I think the snprintf
would win, since rapidjson is designated to a more general use, so more code for format adaption. and your example seems a rather fixed format.
but if taking maintainability, readability and flexiblity into account, rapidjson wins.
either way, you should profile them by yourself, because you know your context better than anyone else
@bethebest0622 Please note that, writing JSON needs doing more things, for example, escaping some characters in string (e.g. if there is a "
inside the string).
the output i need is a json string.
i could use snprintf with:
snprintf(buff, sizeof(buff), "{\"productType\": \"usdt-futures\", \"marginMode\": \"crossed\", \"orderType\": \"limit\", \"marginCoin\": \"USDT\", \"size\":\"%s\", \"price\":\"%s\", \"force\": \"%s\", \"clientOid\": \"%s\", \"side\": \"%s\", \"symbol\": \"%s\"}", .....)
rapidjson provide:could you let me know which one is fast in a frequent-used situation?