Most performant way of converting int to string
Andrew Chapman via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Dec 22 10:15:54 PST 2015
On Tuesday, 22 December 2015 at 18:11:24 UTC, rumbu wrote:
> On Tuesday, 22 December 2015 at 17:15:27 UTC, Andrew Chapman
> wrote:
>> Sorry if this is a silly question but is the to! method from
>> the conv library the most efficient way of converting an
>> integer value to a string?
>>
>> e.g.
>> string s = to!string(100);
>>
>> I'm seeing a pretty dramatic slow down in my code when I use a
>> conversion like this (when looped over 10 million iterations
>> for benchmarking).
>>
>> Cheers!
>
> Converting numbers to string involves the most expensive known
> two operations : division and modulus by 10.
Cool thanks, so essentially it's unavoidable - I have a
background in PHP programming where we don't really get exposed
to memory allocation, conversions etc. Good to learn. Cheers.
More information about the Digitalmars-d-learn
mailing list