Most performant way of converting int to string

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Dec 22 09:43:00 PST 2015


On Tue, Dec 22, 2015 at 05:23:11PM +0000, Andrew Chapman via Digitalmars-d-learn wrote:
[...]
>         for({int i; i = 0;} i < num; i++) {
>                 //string s = to!string(i);
>                 Customer c = Customer(i, "Customer", "99998888", i * 2);
>                 string result = objS.serialize(c);
>         }
> 
> If I uncomment the "string s" line I'm seeing a 20% increase in
> running time, which given what's going on the rest of the code is
> quite surprising.  I've tried compiling with both dmd and ldc2 - it's
> the same under both.
[...]

I wonder if the slowdown is caused by GC collection cycles (because
calling to!string will allocate, and here you're making a very large
number of small allocations, which is known to cause GC performance
issues).

Try inserting this before the loop:

	import core.memory;
	GC.disable();

Does this make a difference in the running time?


T

-- 
"Uhh, I'm still not here." -- KD, while "away" on ICQ.


More information about the Digitalmars-d-learn mailing list