返回资讯中心
外部精选
软件工程
#开发者实时流

Integer to String Conversion (2014)

href=https://www.facebook.com/notes/facebook-engineering/three-optimization-tips-for-c/10151361643253920>posted a function to convert integers to strings that manages to be even faster. They do use the same idea of avoi…

Hacker News 最新jstrieb2026/10/18 · 2026/10/182 分钟阅读

以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。

href=https://www.facebook.com/notes/facebook-engineering/three-optimization-tips-for-c/10151361643253920>posted a function to convert integers to strings that manages to be even faster. They do use the same idea of avoiding having to reverse the string after they're done converting each digit, and they use a lookup table as well.But the nice trick is that, instead of having a lookup table for 10 digits, there's a table for all pair of digits, from 00 to 99. This cuts the amount of divisions by half, yielding a significantly faster algorithm: around 31% faster than the above snippet:size_t facebook_uint32_to_str(uint32_t value, char *dst) { static const char digits[201] =

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →