Casting MapResult

jmh530 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 16 06:06:57 PDT 2015


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.


More information about the Digitalmars-d-learn mailing list