[Performance] Why D's std.string.atoi is 4x slower than std.c.stdlib.atoi?
Burton Radons
burton-radons at smocky.com
Sat Nov 11 12:33:43 PST 2006
Andrey Khropov wrote:
> -------------------------------------------------
> On my machine (P-M 1.7 Dothan) the mean times are:
>
> D-StdLib:1695 ms elapsed (mean).
> C-StdLib:374 ms elapsed (mean).
>
> Why is it so? What could be done?
It's because std.string.atoi is implemented simply with:
return std.c.stdlib.atoi(toStringz(s));
The fault is toStringz - originally that operation tried to tell whether
the string was NUL-terminated, but now it just allocates a copy.
Use std.conv.toInt instead, although from the looks of the
implementation, that will be slightly slower as well.
More information about the Digitalmars-d
mailing list