[Performance] std.conv.toInt is damn fast!
Andrey Khropov
andkhropov_nosp at m_mtu-net.ru
Sat Nov 11 13:44:37 PST 2006
Burton Radons wrote:
> Use std.conv.toInt instead, although from the looks of the implementation,
> that will be slightly slower as well.
Thanks for the advice. As a matter of fact it is faster than C's atoi!
And better handles errors (through exceptions)
D-std.conv.toInt: 277 ms elapsed (mean).
vs
D-std.c.stdlib.atoi: 348 ms elapsed (mean).
And it's really the fastest implementation among the different languages std
libraries:
Here is the list of results for different languages and implementations
(all optimization options were turned to the maximum):
1) DMD 0.173 (toInt) - 0.277 sec
2) MinGW GCC 3.4.2 (atoi) - 0.345 sec
3) MS VC++ 8.0 (atoi) - 0.645 sec
4) C# on Mono 1.1.18 (int.Parse) - 1.023 sec
5) Java on HotSpot 1.5.0_08 (Integer.decode) - 1.796 sec (-server)
6) Java on JRockit 26.4.0 (Integer.decode) - 1.969 sec (-server, that's the
mean for 5 runs, first run (when Jitting is performed) is 2.905 sec)
7) C# on .NET 2.0 (int.Parse) - 2.899 sec (haven't yet downloaded .NET 3.0)
8) CPython 2.4.2 + Psyco 1.5 (int()) - 5.406 sec
9) IronPython 1.0 on Mono 1.1.18 (int()) - 10.625 sec
10) IronPython 1.0 on .NET 2.0 (int()) - 10.685 sec
11) CPython 2.4.2 (int()) - 11.218 sec
12) MinGW GCC 3.4.2
(boost 1.33.1::lexical_cast<int>) - 21.305 sec
13) MS VC++ 8.0
(boost 1.33.1::lexical_cast<int>) - 51.700 sec (Yes, it's hard to believe
but check yourself!)
I actually cannot believe it, but D's std.conv.toInt is almost 100x faster than
boost version!
--
AKhropov
More information about the Digitalmars-d
mailing list