Performance of ranges verses direct
Joseph Rushton Wakeling
joseph.wakeling at webdrake.net
Wed Dec 11 08:40:39 PST 2013
On 11/12/13 11:10, John Colvin wrote:
> A lot of the performance loss is down to missed optimisations, in particular
> inlining.
Simple example:
foreach(i; iota(0, 10)) { ... }
should be as fast as
foreach(i; 0 .. 10) { ... }
but isn't. I remember Andrei noting that this ought to be easily fixable [*],
but I don't know if that actually happened, because I haven't compared the two
recently.
[* If I recall right, it's achievable by special-casing iota when the increment
is 1, but don't quote me on that.]
> General advice: use ranges, std.range and std.algorithm wherever possible.
> Profile the resulting code and write out the hotspots in an imperative style to
> see if you can squeeze out some extra speed.
Yes -- use ranges as much as possible because the resulting code will be so much
easier to read and maintain. Switching to imperative style is only worth it if
there's a speed problem (read: "The speed is unsatisfactory for your use case
and/or inferior to rival programs doing the same thing.").
More information about the Digitalmars-d-learn
mailing list