Re: Most performant way of converting int to string

2015-12-24 Thread Ivan Kazmenko via Digitalmars-d-learn
On Tuesday, 22 December 2015 at 19:50:28 UTC, Daniel Kozák wrote: V Tue, 22 Dec 2015 18:39:16 + Ivan Kazmenko via Digitalmars-d-learn napsáno: Does DMD, or Phobos function to!(string), do anything like that? The number of possible bases is not large

Re: Most performant way of converting int to string

2015-12-23 Thread Jakob Ovrum via Digitalmars-d-learn
On Tuesday, 22 December 2015 at 17:23:11 UTC, Andrew Chapman wrote: On Tuesday, 22 December 2015 at 17:18:16 UTC, cym13 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

Re: Most performant way of converting int to string

2015-12-23 Thread Jakob Ovrum via Digitalmars-d-learn
On Wednesday, 23 December 2015 at 11:21:32 UTC, Jakob Ovrum wrote: Dynamic memory allocation is expensive. If the string is short-lived, allocate it on the stack: See also std.conv.toChars[1] for stringifying lazily/on-demand. http://dlang.org/phobos/std_conv#toChars

Re: Most performant way of converting int to string

2015-12-23 Thread Ali Çehreli via Digitalmars-d-learn
On 12/23/2015 02:29 PM, Andrew Chapman wrote: > string v = toChars!(16,char,LetterCase.lower)(i); > > to convert an integer to Hex for example, but the compiler wasn't happy > with it. How would I convert an int to a string using this? I had to squint at the error message to understand that

Re: Most performant way of converting int to string

2015-12-23 Thread Andrew Chapman via Digitalmars-d-learn
On Wednesday, 23 December 2015 at 11:46:37 UTC, Jakob Ovrum wrote: On Wednesday, 23 December 2015 at 11:21:32 UTC, Jakob Ovrum wrote: Dynamic memory allocation is expensive. If the string is short-lived, allocate it on the stack: See also std.conv.toChars[1] for stringifying lazily/on-demand.

Re: Most performant way of converting int to string

2015-12-23 Thread Minas Mina via Digitalmars-d-learn
On Wednesday, 23 December 2015 at 22:29:31 UTC, Andrew Chapman wrote: On Wednesday, 23 December 2015 at 11:46:37 UTC, Jakob Ovrum wrote: On Wednesday, 23 December 2015 at 11:21:32 UTC, Jakob Ovrum wrote: Dynamic memory allocation is expensive. If the string is short-lived, allocate it on the

Re: Most performant way of converting int to string

2015-12-22 Thread Daniel Kozák via Digitalmars-d-learn
V Tue, 22 Dec 2015 18:39:16 + Ivan Kazmenko via Digitalmars-d-learn napsáno: > 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

Re: Most performant way of converting int to string

2015-12-22 Thread Daniel Kozák via Digitalmars-d-learn
V Tue, 22 Dec 2015 18:11:24 + rumbu via Digitalmars-d-learn napsáno: > 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

Re: Most performant way of converting int to string

2015-12-22 Thread rumbu via Digitalmars-d-learn
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

Re: Most performant way of converting int to string

2015-12-22 Thread Daniel Kozák via Digitalmars-d-learn
V Tue, 22 Dec 2015 17:15:27 + Andrew Chapman via Digitalmars-d-learn napsáno: > 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 =

Re: Most performant way of converting int to string

2015-12-22 Thread Daniel Kozák via Digitalmars-d-learn
V Tue, 22 Dec 2015 20:52:07 + rumbu via Digitalmars-d-learn napsáno: > On Tuesday, 22 December 2015 at 19:45:46 UTC, Daniel Kozák wrote: > > V Tue, 22 Dec 2015 18:11:24 + > > rumbu via Digitalmars-d-learn > > > >

Re: Most performant way of converting int to string

2015-12-22 Thread Andrew Chapman via Digitalmars-d-learn
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 =

Re: Most performant way of converting int to string

2015-12-22 Thread rumbu via Digitalmars-d-learn
On Tuesday, 22 December 2015 at 20:52:07 UTC, rumbu wrote: On Tuesday, 22 December 2015 at 19:45:46 UTC, Daniel Kozák wrote: V Tue, 22 Dec 2015 18:11:24 + rumbu via Digitalmars-d-learn napsáno: On Tuesday, 22 December 2015 at 17:15:27 UTC, Andrew

Re: Most performant way of converting int to string

2015-12-22 Thread H. S. Teoh via Digitalmars-d-learn
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" > napsáno: > > > On Tue, Dec 22, 2015 at 05:23:11PM +, Andrew Chapman via > >

Re: Most performant way of converting int to string

2015-12-22 Thread Daniel Kozák via Digitalmars-d-learn
V Tue, 22 Dec 2015 21:10:54 + rumbu via Digitalmars-d-learn napsáno: > On Tuesday, 22 December 2015 at 20:52:07 UTC, rumbu wrote: > > On Tuesday, 22 December 2015 at 19:45:46 UTC, Daniel Kozák > > wrote: > >> V Tue, 22 Dec 2015 18:11:24 + > >> rumbu

Re: Most performant way of converting int to string

2015-12-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/22/15 12:15 PM, 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

Re: Most performant way of converting int to string

2015-12-22 Thread Daniel Kozak via Digitalmars-d-learn
On Tuesday, 22 December 2015 at 18:27:12 UTC, cym13 wrote: ... I don't think there is anything in the standard library that would really help here as (if I read it correctly) it is mainly because of the conversion from ranges to arrays that this code is slow. Yes, it has been faster in past,

Re: Most performant way of converting int to string

2015-12-22 Thread Ali Çehreli via Digitalmars-d-learn
On 12/22/2015 10:15 AM, Andrew Chapman wrote: > On Tuesday, 22 December 2015 at 18:11:24 UTC, rumbu wrote: >> Converting numbers to string involves the most expensive known two >> operations : division and modulus by 10. > > Cool thanks, so essentially it's unavoidable There is hope. :) > I

Re: Most performant way of converting int to string

2015-12-22 Thread Ivan Kazmenko via Digitalmars-d-learn
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 =

Re: Most performant way of converting int to string

2015-12-22 Thread Daniel Kozák via Digitalmars-d-learn
V Tue, 22 Dec 2015 09:43:00 -0800 "H. S. Teoh via Digitalmars-d-learn" napsáno: > On Tue, Dec 22, 2015 at 05:23:11PM +, Andrew Chapman via > Digitalmars-d-learn wrote: [...] > > for({int i; i = 0;} i < num; i++) { > > //string s =

Re: Most performant way of converting int to string

2015-12-22 Thread Andrew Chapman via Digitalmars-d-learn
On Tuesday, 22 December 2015 at 17:43:00 UTC, H. S. Teoh wrote: 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

Re: Most performant way of converting int to string

2015-12-22 Thread Daniel Kozák via Digitalmars-d-learn
V Tue, 22 Dec 2015 12:55:10 -0800 "H. S. Teoh via Digitalmars-d-learn" 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" > >

Re: Most performant way of converting int to string

2015-12-22 Thread cym13 via Digitalmars-d-learn
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

Re: Most performant way of converting int to string

2015-12-22 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 22, 2015 at 05:23:11PM +, 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", "", i * 2); > string result =

Re: Most performant way of converting int to string

2015-12-22 Thread Andrew Chapman via Digitalmars-d-learn
On Tuesday, 22 December 2015 at 17:18:16 UTC, cym13 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 =

Re: Most performant way of converting int to string

2015-12-22 Thread cym13 via Digitalmars-d-learn
On Tuesday, 22 December 2015 at 17:52:52 UTC, Andrew Chapman wrote: On Tuesday, 22 December 2015 at 17:43:00 UTC, H. S. Teoh wrote: 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

Re: Most performant way of converting int to string

2015-12-22 Thread rumbu via Digitalmars-d-learn
On Tuesday, 22 December 2015 at 19:45:46 UTC, Daniel Kozák wrote: V Tue, 22 Dec 2015 18:11:24 + rumbu via Digitalmars-d-learn napsáno: On Tuesday, 22 December 2015 at 17:15:27 UTC, Andrew Chapman wrote: > Sorry if this is a silly question but is the