3 ms·
Great hack, but in a broader sense this is silly. If parsing/pretty-printing floats from/to ASCII strings is a bottleneck you should be using hexfloats, as supp
by zozbot234 7y ago
Great hack, but in a broader sense this is silly. If parsing/pretty-printing floats from/to ASCII strings is a bottleneck you should be using hexfloats, as supported in the latest C/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.
- chadaustin 7y agoIt can be a big chunk of the cost of parsing JSON.
- gameswithgo 7y agostop using json is the message
- blacklion 7y agoI dream about day when all cryptoexchanges get this message. Not today :-(
- thedance 7y agoIt's not silly at all. Replacing a lot of sprintf calls with Grisu and later Ryu made a huge difference in the production fleet at my last job. It wasn't by any means "the bottleneck" but it was costing real money. Most of the calls were in peripheral functions like debug logs, status page outputs, and whatnot. That said, I've never seen strtod showing up in my profiles, but I bet if I was profiling web browsers then I would see it.
- MaxBarraclough 7y agoI was wondering if ctrl-f for 'Ryu' would match anything. Jeroen van der Zijp, developer of the lesser known FOX Toolkit, claims to have done better than the Ryu algorithm. From his changelist [0]: > New, faster, and often more accurate floating point to string conversion. No, this is not based on Ryu paper. New method reliably generates 16 digits, and does much better rounding. I believe this [1] is his implementation in C++. See also his paper [2]. (I believe it's not peer-reviewed, but it does appear in Google Scholar.) [0] http://www.fox-toolkit.org/ http://www.fox-toolkit.org/ [1] https://github.com/gogglesguy/fox/blob/77396c638c1c4e05/lib/fxprintf.cpp#L381 https://github.com/gogglesguy/fox/blob/77396c638c1c4e05/lib/... [2] http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf
- zone411 7y agoThis conversion was a profiler-verified bottleneck in my projects twice. Nothing silly about it.