TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Fast function to parse strings into double (binary64) floating-point values

73 点作者 vitaut大约 5 年前

10 条评论

scottlamb大约 5 年前
It has about 15 KB of data: 10KB in power_of_ten_components and 5KB in mantissa_128. [1] That&#x27;s ~23% of the per-core L1 data cache on (eg) the recently announced APU chip. [2, 3] So before getting too excited about the microbenchmark numbers, I&#x27;d be careful to ensure the additional cache pressure doesn&#x27;t slow down my program as a whole.<p>edit: also, ~2.5KB of that is due to padding in power_of_ten_components. I wonder if it&#x27;d be better to split the uint64_t field into two uint32_ts to avoid this.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;lemire&#x2F;fast_double_parser&#x2F;blob&#x2F;master&#x2F;include&#x2F;fast_double_parser.h" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;lemire&#x2F;fast_double_parser&#x2F;blob&#x2F;master&#x2F;inc...</a> [2] <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=22440894" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=22440894</a> [3] <a href="https:&#x2F;&#x2F;en.wikichip.org&#x2F;wiki&#x2F;amd&#x2F;ryzen_embedded&#x2F;r1606g" rel="nofollow">https:&#x2F;&#x2F;en.wikichip.org&#x2F;wiki&#x2F;amd&#x2F;ryzen_embedded&#x2F;r1606g</a>
评论 #22541551 未加载
评论 #22544244 未加载
plus大约 5 年前
&gt; That is, given the string &quot;1.0e10&quot;, it should return a 64-bit floating-point value equal to 10.<p>Err, surely it should be equal to 10,000,000,000. Or more probably, they meant to write &quot;1.0e1&quot;.
评论 #22544443 未加载
eesmith大约 5 年前
More context at Daniel Lemire&#x27;s blog post at <a href="https:&#x2F;&#x2F;lemire.me&#x2F;blog&#x2F;2020&#x2F;03&#x2F;10&#x2F;fast-float-parsing-in-practice&#x2F;" rel="nofollow">https:&#x2F;&#x2F;lemire.me&#x2F;blog&#x2F;2020&#x2F;03&#x2F;10&#x2F;fast-float-parsing-in-prac...</a> . It&#x27;s about twice as fast as abseil or from_chars and nearly 10x faster than strtod.
londons_explore大约 5 年前
I was expecting this to include fancy bit twiddling and simd assembly for parsing 8 decimal digits at once...<p>But the reality is the core of the algorithm is still a while loop that looks at each digit one at a time and multiplies by 10 each time ...
zone411大约 5 年前
Shouldn&#x27;t std::from_chars be included in the benchmarks?
评论 #22543208 未加载
voldacar大约 5 年前
Is there a site out there that collects the absolute fastest ways of doing common low-level operations like this? For something as common as converting strings of digits to IEEE 754 floats&#x2F;doubles, you would think we would already have the absolute fastest sequence of assembly instructions to do this. It&#x27;s disconcerting thinking that the functions in the standard c&#x2F;c++ library may not even be close to optimal.<p>Very cool btw
评论 #22542456 未加载
zozbot234大约 5 年前
Great hack, but in a broader sense this is silly. If parsing&#x2F;pretty-printing floats from&#x2F;to ASCII strings is a bottleneck you should be using hexfloats, as supported in the latest C&#x2F;C++ standards and elsewhere. As a bonus, they will reliably evaluate to the same floating point number, eliminating an extra source of ambiguity and possible overhead.
评论 #22541798 未加载
评论 #22542366 未加载
评论 #22542472 未加载
alkonaut大约 5 年前
What&#x27;s a scenario where you have a huge flow of floating point data as text? Assuming it&#x27;s usually json, but in which case does that happen and you need to work around it (parse faster) rather than fix the underlying problem of having a huge stream of numbers as <i>text</i>?
评论 #22546703 未加载
roel_v大约 5 年前
Would having a mode that restricts the types of numbers it accepts (in my particular case: no scientific notation) speed it up significantly?
abductee_hg大约 5 年前
bad. you should not do that at all.
评论 #22543774 未加载