Most performant way of converting int to string
Ivan Kazmenko via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Dec 24 10:01:44 PST 2015
On Tuesday, 22 December 2015 at 19:50:28 UTC, Daniel Kozák wrote:
> V Tue, 22 Dec 2015 18:39:16 +0000
> Ivan Kazmenko via Digitalmars-d-learn
> <digitalmars-d-learn at puremagic.com> napsáno:
>> Does DMD, or Phobos function to!(string), do anything like
>> that? The number of possible bases is not large anyway. I've
>> heard major C/C++ compilers do that, but have not looked for a
>> proof myself.
> Yes, IIRC, all D compilers should be able to change modulus and
> division to few additions, subtractions and bit shifts if base
> is known at compile time.
> And phobos use this:
So, in a few common cases (bases 10 and 2, 4, 8, 16), you convert
a runtime argument into a compile-time argument for the
implementation function, and there, division is optimized at
compile time. Nice!
More information about the Digitalmars-d-learn