It's tricky... at maximum precision, the last digit does no longer follow the engineer's rule that it should be rounded correctly. I was inspired to time these after reading this on SOF (https://stackoverflow.com/questions/39615201/fastest-double-to-string-conversion):
QuoteTry Ryƫ's (https://github.com/ulfjack/ryu) fast float-to-string conversion algorithm (https://www.youtube.com/watch?v=kw-U6smcLzk), which also has a double-tostring implementation
Ulf Adams in his YouTube video (https://www.youtube.com/watch?v=kw-U6smcLzk) says that the JavaScript implementation is about 10,000 lines long, so for the time being I'll be modest and restrict the analysis to what we already have in Masm32, MasmBasic and the CRT :cool:
Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz
1.234568 24 ms for FloatToStr (default precision)
1.234568 20 ms for MasmBasic Str$()
1.234568 68 ms for CRT sprintf
1.2345678901234567890 double passed, max resolution:
1.2345678901234566 24 ms for FloatToStr2 (max precision)
1.234567890123457 36 ms for MasmBasic Str$()
1.234567890123457 75 ms for CRT sprintf
1.2345678901234567 25 ms for Str$() beyond good
1.2345678901234567 75 ms for sprintf beyond good
1.234568 23 ms for FloatToStr (default precision)
1.234568 19 ms for MasmBasic Str$()
1.234568 62 ms for CRT sprintf
1.2345678901234567890 double passed, max resolution:
1.2345678901234566 23 ms for FloatToStr2 (max precision)
1.234567890123457 37 ms for MasmBasic Str$()
1.234567890123457 73 ms for CRT sprintf
1.2345678901234567 25 ms for Str$() beyond good
1.2345678901234567 75 ms for sprintf beyond good
1.234568 22 ms for FloatToStr (default precision)
1.234568 18 ms for MasmBasic Str$()
1.234568 63 ms for CRT sprintf
1.2345678901234567890 double passed, max resolution:
1.2345678901234566 23 ms for FloatToStr2 (max precision)
1.234567890123457 40 ms for MasmBasic Str$()
1.234567890123457 86 ms for CRT sprintf
1.2345678901234567 25 ms for Str$() beyond good
1.2345678901234567 75 ms for sprintf beyond good
I had to add a .bat file,so it didnt run and exit without pause
also interested in fast biginteger->ascii,BCD->ascii timings OR vs ORPS speed
Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
1.234568 22 ms for FloatToStr (default precision)
1.234568 18 ms for MasmBasic Str$()
1.234568 60 ms for CRT sprintf
1.2345678901234567890 double passed, max resolution:
1.2345678901234566 23 ms for FloatToStr2 (max precision)
1.234567890123457 35 ms for MasmBasic Str$()
1.234567890123457 70 ms for CRT sprintf
1.2345678901234567 21 ms for Str$() beyond good
1.2345678901234567 67 ms for sprintf beyond good
1.234568 21 ms for FloatToStr (default precision)
1.234568 17 ms for MasmBasic Str$()
1.234568 61 ms for CRT sprintf
1.2345678901234567890 double passed, max resolution:
1.2345678901234566 21 ms for FloatToStr2 (max precision)
1.234567890123457 35 ms for MasmBasic Str$()
1.234567890123457 67 ms for CRT sprintf
1.2345678901234567 21 ms for Str$() beyond good
1.2345678901234567 65 ms for sprintf beyond good
1.234568 21 ms for FloatToStr (default precision)
1.234568 17 ms for MasmBasic Str$()
1.234568 56 ms for CRT sprintf
1.2345678901234567890 double passed, max resolution:
1.2345678901234566 22 ms for FloatToStr2 (max precision)
1.234567890123457 37 ms for MasmBasic Str$()
1.234567890123457 68 ms for CRT sprintf
1.2345678901234567 21 ms for Str$() beyond good
1.2345678901234567 65 ms for sprintf beyond good
AMD Ryzen 5 2400G with Radeon Vega Graphics
1.234568 18 ms for FloatToStr (default precision)
1.234568 18 ms for MasmBasic Str$()
1.234568 52 ms for CRT sprintf
1.2345678901234567890 double passed, max resolution:
1.2345678901234566 13 ms for FloatToStr2 (max precision)
1.234567890123457 27 ms for MasmBasic Str$()
1.234567890123457 68 ms for CRT sprintf
1.2345678901234567 17 ms for Str$() beyond good
1.2345678901234567 65 ms for sprintf beyond good
1.234568 13 ms for FloatToStr (default precision)
1.234568 14 ms for MasmBasic Str$()
1.234568 53 ms for CRT sprintf
1.2345678901234567890 double passed, max resolution:
1.2345678901234566 24 ms for FloatToStr2 (max precision)
1.234567890123457 32 ms for MasmBasic Str$()
1.234567890123457 94 ms for CRT sprintf
1.2345678901234567 25 ms for Str$() beyond good
1.2345678901234567 104 ms for sprintf beyond good
1.234568 20 ms for FloatToStr (default precision)
1.234568 21 ms for MasmBasic Str$()
1.234568 88 ms for CRT sprintf
1.2345678901234567890 double passed, max resolution:
1.2345678901234566 23 ms for FloatToStr2 (max precision)
1.234567890123457 27 ms for MasmBasic Str$()
1.234567890123457 70 ms for CRT sprintf
1.2345678901234567 18 ms for Str$() beyond good
1.2345678901234567 66 ms for sprintf beyond good
is it possible make a SIMD conversion?
similar to this:
http://masm32.com/board/index.php?topic=9636.0 (http://masm32.com/board/index.php?topic=9636.0)
also way to speed up conversion of this:
http://masm32.com/board/index.php?topic=9773.0 (http://masm32.com/board/index.php?topic=9773.0)
Quote from: daydreamer on February 20, 2022, 06:27:55 AM
is it possible make a SIMD conversion?
Probably - go ahead :thumbsup:
11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
1.234568 15 ms for FloatToStr (default precision)
1.234568 17 ms for MasmBasic Str$()
1.234568 39 ms for CRT sprintf
1.2345678901234567890 double passed, max resolution:
1.2345678901234566 16 ms for FloatToStr2 (max precision)
1.234567890123457 28 ms for MasmBasic Str$()
1.234567890123457 43 ms for CRT sprintf
1.2345678901234567 16 ms for Str$() beyond good
1.2345678901234567 42 ms for sprintf beyond good
1.234568 15 ms for FloatToStr (default precision)
1.234568 13 ms for MasmBasic Str$()
1.234568 39 ms for CRT sprintf
1.2345678901234567890 double passed, max resolution:
1.2345678901234566 16 ms for FloatToStr2 (max precision)
1.234567890123457 29 ms for MasmBasic Str$()
1.234567890123457 42 ms for CRT sprintf
1.2345678901234567 15 ms for Str$() beyond good
1.2345678901234567 42 ms for sprintf beyond good
1.234568 15 ms for FloatToStr (default precision)
1.234568 12 ms for MasmBasic Str$()
1.234568 38 ms for CRT sprintf
1.2345678901234567890 double passed, max resolution:
1.2345678901234566 16 ms for FloatToStr2 (max precision)
1.234567890123457 29 ms for MasmBasic Str$()
1.234567890123457 49 ms for CRT sprintf
1.2345678901234567 18 ms for Str$() beyond good
1.2345678901234567 53 ms for sprintf beyond good
Thanks. There are some oddities with rounding, too:
include \masm32\MasmBasic\MasmBasic.inc
SetGlobals TheDouble:REAL8=0.6574268070980906486, buffer[100]:BYTE
Init
Cls
PrintLine "expected:", Tb$, "0.6574268070980906486"
Print Str$("Str$: \t%If\n", TheDouble)
Print cfm$("FloatToStr:\t")
invoke FloatToStr2, TheDouble, addr buffer
lea ecx, buffer
PrintLine ecx
invoke crt_sprintf, addr buffer, cfm$("sprintf:\t%1.19f\n"), TheDouble
lea ecx, buffer
Print ecx
Inkey "hit any key"
EndOfCode
expected: 0.6574268070980906486
Str$: 0.657426807098090649
FloatToStr: 0.6574268070980905
sprintf: 0.6574268070980906500
FloatToStr is a bit off, and sprintf should display ..490, not ..500
See WolframAlpha for exact roundings (https://www.wolframalpha.com/widgets/view.jsp?id=c0da153a42f724454914583e91772bc7)
:biggrin:
Suggestion, put a wait at the end so it can be run without opening a console and typing the file name. :eusa_pray:
Intel(R) Core(TM) i7-5820K CPU @ 3.30GHz clocked at 4 gig.
1.234568 17 ms for FloatToStr (default precision)
1.234568 12 ms for MasmBasic Str$()
1.234568 45 ms for CRT sprintf
1.2345678901234567890 double passed, max resolution:
1.2345678901234566 16 ms for FloatToStr2 (max precision)
1.234567890123457 26 ms for MasmBasic Str$()
1.234567890123457 50 ms for CRT sprintf
1.2345678901234567 16 ms for Str$() beyond good
1.2345678901234567 51 ms for sprintf beyond good
1.234568 16 ms for FloatToStr (default precision)
1.234568 12 ms for MasmBasic Str$()
1.234568 45 ms for CRT sprintf
1.2345678901234567890 double passed, max resolution:
1.2345678901234566 16 ms for FloatToStr2 (max precision)
1.234567890123457 26 ms for MasmBasic Str$()
1.234567890123457 50 ms for CRT sprintf
1.2345678901234567 16 ms for Str$() beyond good
1.2345678901234567 51 ms for sprintf beyond good
1.234568 16 ms for FloatToStr (default precision)
1.234568 12 ms for MasmBasic Str$()
1.234568 44 ms for CRT sprintf
1.2345678901234567890 double passed, max resolution:
1.2345678901234566 16 ms for FloatToStr2 (max precision)
1.234567890123457 27 ms for MasmBasic Str$()
1.234567890123457 50 ms for CRT sprintf
1.2345678901234567 16 ms for Str$() beyond good
1.2345678901234567 51 ms for sprintf beyond good
Testing the new computer... Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz
Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz
1.234568 16 ms for FloatToStr (default precision)
1.234568 13 ms for MasmBasic Str$()
1.234568 42 ms for CRT sprintf
1.2345678901234567890 double passed, max resolution:
1.2345678901234566 16 ms for FloatToStr2 (max precision)
1.234567890123457 25 ms for MasmBasic Str$()
1.234567890123457 47 ms for CRT sprintf
1.2345678901234567 17 ms for Str$() beyond good
1.2345678901234567 50 ms for sprintf beyond good
1.234568 16 ms for FloatToStr (default precision)
1.234568 13 ms for MasmBasic Str$()
1.234568 41 ms for CRT sprintf
1.2345678901234567890 double passed, max resolution:
1.2345678901234566 16 ms for FloatToStr2 (max precision)
1.234567890123457 26 ms for MasmBasic Str$()
1.234567890123457 46 ms for CRT sprintf
1.2345678901234567 16 ms for Str$() beyond good
1.2345678901234567 47 ms for sprintf beyond good
1.234568 16 ms for FloatToStr (default precision)
1.234568 12 ms for MasmBasic Str$()
1.234568 43 ms for CRT sprintf
1.2345678901234567890 double passed, max resolution:
1.2345678901234566 16 ms for FloatToStr2 (max precision)
1.234567890123457 27 ms for MasmBasic Str$()
1.234567890123457 46 ms for CRT sprintf
1.2345678901234567 16 ms for Str$() beyond good
1.2345678901234567 46 ms for sprintf beyond good
C:\Users\user1\Desktop>pause
Press any key to continue . . .
:biggrin:
My new laptop for comparison:
Intel(R) Celeron(R) N5105 @ 2.00GHz
1.234568 25 ms for FloatToStr (default precision)
1.234568 21 ms for MasmBasic Str$()
1.234568 64 ms for CRT sprintf
1.2345678901234567890 double passed, max resolution:
1.2345678901234566 24 ms for FloatToStr2 (max precision)
1.234567890123457 46 ms for MasmBasic Str$()
1.234567890123457 71 ms for CRT sprintf
1.2345678901234567 25 ms for Str$() beyond good
1.2345678901234567 73 ms for sprintf beyond good
1.234568 25 ms for FloatToStr (default precision)
1.234568 20 ms for MasmBasic Str$()
1.234568 62 ms for CRT sprintf
1.2345678901234567890 double passed, max resolution:
1.2345678901234566 24 ms for FloatToStr2 (max precision)
1.234567890123457 45 ms for MasmBasic Str$()
1.234567890123457 72 ms for CRT sprintf
1.2345678901234567 25 ms for Str$() beyond good
1.2345678901234567 72 ms for sprintf beyond good
1.234568 24 ms for FloatToStr (default precision)
1.234568 20 ms for MasmBasic Str$()
1.234568 63 ms for CRT sprintf
1.2345678901234567890 double passed, max resolution:
1.2345678901234566 25 ms for FloatToStr2 (max precision)
1.234567890123457 46 ms for MasmBasic Str$()
1.234567890123457 72 ms for CRT sprintf
1.2345678901234567 25 ms for Str$() beyond good
1.2345678901234567 71 ms for sprintf beyond good
C:\Users\Administrator\Desktop>pause
Press any key to continue . . .
I am a happy camper, both with the laptop and the new desktop computer. :biggrin: :biggrin:
For completeness, my tired old desktop computer:
Intel(R) Core(TM)2 Duo CPU E8400 @ 3.00GHz
1.234568 22 ms for FloatToStr (default precision)
1.234568 25 ms for MasmBasic Str$()
1.234568 75 ms for CRT sprintf
1.2345678901234567890 double passed, max resolution:
1.2345678901234566 22 ms for FloatToStr2 (max precision)
1.234567890123457 38 ms for MasmBasic Str$()
1.234567890123457 86 ms for CRT sprintf
1.2345678901234567 26 ms for Str$() beyond good
1.2345678901234567 85 ms for sprintf beyond good
1.234568 22 ms for FloatToStr (default precision)
1.234568 20 ms for MasmBasic Str$()
1.234568 76 ms for CRT sprintf
1.2345678901234567890 double passed, max resolution:
1.2345678901234566 22 ms for FloatToStr2 (max precision)
1.234567890123457 38 ms for MasmBasic Str$()
1.234567890123457 84 ms for CRT sprintf
1.2345678901234567 26 ms for Str$() beyond good
1.2345678901234567 84 ms for sprintf beyond good
1.234568 22 ms for FloatToStr (default precision)
1.234568 20 ms for MasmBasic Str$()
1.234568 75 ms for CRT sprintf
1.2345678901234567890 double passed, max resolution:
1.2345678901234566 22 ms for FloatToStr2 (max precision)
1.234567890123457 40 ms for MasmBasic Str$()
1.234567890123457 85 ms for CRT sprintf
1.2345678901234567 26 ms for Str$() beyond good
1.2345678901234567 86 ms for sprintf beyond good
C:\Users\Administrator\Desktop>pause
Press any key to continue . . .
I am available for some more algo speed testing... :wink2:
I Was on my way starting new timings thread,as part of my prime test optimisation, different sqrt,div,mul ,but found a thread and please everyone who has got newer computer run timings with newer or run timings with CPU that isn't already in that thread
https://masm32.com/board/index.php?topic=6798.0
Quote from: daydreamer on January 02, 2025, 10:23:46 PMI Was on my way starting new timings thread,as part of my prime test optimisation, different sqrt,div,mul ,but found a thread and please everyone who has got newer computer run timings with newer or run timings with CPU that isn't already in that thread
https://masm32.com/board/index.php?topic=6798.0 (https://masm32.com/board/index.php?topic=6798.0)
Will run that test when I get back to my computer/laptop. My iPad refuses to run Windows executables. :tongue:
Fixed the link in the quoted text. :wink2: ...hint, hint...