Replacement for snprintf
dlang at d-ecke.de
Thu Oct 31 21:14:15 UTC 2019
On Wednesday, 30 October 2019 at 20:46:07 UTC, Stefan Koch wrote:
> If you could post that so I can have a look over the WIP that'd
> be nice.
The function can be found at the end of std/format.d. I had to
comment out some unittests, because e and g qualifiers are not
yet supported. I put several comments in the code, so I hope it's
clear, what always happens. If not, feel free to ask. (I'll be
offline during the weekend.)
I also added a diagram for speed comparison. See
Blue and green use "%.10f" while black and red use "%.100f". Blue
and red is my function, while green and black is snprintf. The
X-axis gives the value in the exponent from 0 to 255, the y-axis
gives the average time in nanoseconds. The green bottom line at
the left is approx at 600ns. For each exponent there have been
approx 217886 numbers checked (the same set for both functions).
As you can see, at the left side, snprintf is faster, having an
almost constant time, while the time of mine is slightly
increasing when exponents get smaller. I scanned the snprintf
implementation to find out, what they do - see my comment in the
implementation for details.
More information about the Digitalmars-d