News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Double to string timings

Started by jj2007, February 17, 2022, 02:51:11 PM

Previous topic - Next topic

jj2007

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:

QuoteTry Ryƫ's fast float-to-string conversion algorithm, which also has a double-tostring implementation

Ulf Adams in his YouTube video 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

daydreamer

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
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

guga

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

Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

daydreamer

#3
is it possible make a SIMD conversion?
similar to this:
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

my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

jj2007


LiaoMi

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

jj2007

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

hutch--

 :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