Most performant way of converting int to string
Daniel Kozák via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Dec 22 14:14:19 PST 2015
V Tue, 22 Dec 2015 12:55:10 -0800
"H. S. Teoh via Digitalmars-d-learn"
<digitalmars-d-learn at puremagic.com> napsáno:
> On Tue, Dec 22, 2015 at 08:54:35PM +0100, Daniel Kozák via
> Digitalmars-d-learn wrote:
> > V Tue, 22 Dec 2015 09:43:00 -0800
> > "H. S. Teoh via Digitalmars-d-learn"
> > <digitalmars-d-learn at puremagic.com> napsáno:
> >
> > > 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
> > >
> > This would not help. It would probably be worse.
>
> I was not suggesting this as a solution, it's merely a way to
> determine whether the performance issue is GC-related.
>
>
> T
>
Ok :)
More information about the Digitalmars-d-learn
mailing list