Casting MapResult
John Colvin via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jun 16 06:15:03 PDT 2015
On Tuesday, 16 June 2015 at 13:06:58 UTC, jmh530 wrote:
> On Monday, 15 June 2015 at 22:40:31 UTC, Baz wrote:
>
>> Right, my bad. This one whould work:
>>
>> ---
>> float[] test(float[] x) {
>> auto result = x.dup;
>> result.each!((ref a) => (a = exp(a)));
>> return result;
>> }
>> ---
>
> That works. Thanks.
>
> I did some benchmarking and found that map tended to be faster
> than each. For some large arrays, it was exceptionally faster.
> Perhaps it has to do with the extra copying in the each formula?
>
> I also did an alternative to each using foreach and they were
> exactly the same speed.
Range based code is very dependant on aggressive optimisation to
get good performance. DMD does a pretty bad/patchy job of this,
LDC and and GDC will normally give you more consistently* fast
code.
*consistent as in different implementations performing very
similarly instead of seeing big differences like you have here.
More information about the Digitalmars-d-learn
mailing list