std.algorithm issue

Dee Girl deegirl at noreply.com
Sat May 24 17:23:25 PDT 2008


bearophile Wrote:

> More versions with more surprises:
> 
>     t = clock();
>     for (uint i; i < 100U; ++i)
>         r = Map2!((int x) {return -x;})(data);
>     putr("Map2 with locally defined delegate: ", clock() - t, " ", r[$-1]);
> 
>     t = clock();
>     for (uint i; i < 100U; ++i)
>         r = Map2!(function(int x) {return -x;})(data);
>     putr("Map2 with locally defined function: ", clock() - t, " ", r[$-1]);
> }
> 
> /*
> 
> Timings:
>     inline: 4.61 -5999999
>     map global func: 4.968 -5999999
>     map locally defined delegate: 4.782 -5999999
>     map locally defined function: 4.328 -5999999
>     Map2 with global function: 4 -5999999
>     inline C malloc: 2.015
>     Map3 with global function: 2.531 -5999999
>     Map4 with global function: 1.969
>     Map2 with locally defined delegate: 4.297 -5999999
>     Map2 with locally defined function: 4.156 -5999999

I think you want to measure function call overhead. Then do not put dynamic allocation in function. Otherwise you measure allocate speed. That is why results are odd. Maybe if you change order results will change.

Would help to put static allocation inside function, never dynamic. Then you measure loop and call overhead. Also tests should be in separate runs of program and averaged over few runs. Dee Girl



More information about the Digitalmars-d mailing list