DMD 0.174 release
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Thu Nov 16 13:27:14 PST 2006
Chris Nicholson-Sauls wrote:
> Jarrett Billingsley wrote:
>
>> "Reiner Pope" <reiner.pope at REMOVE.THIS.gmail.com> wrote in message
>> news:ejg8qd$475$1 at digitaldaemon.com...
>>
>>> Jarrett Billingsley wrote:
>>
>>
>>
>>> I'm not sure if this is what you want, but here's a cast-free 'call'
>>> function:
>>>
>>> ...code...
>>
>>
>>
>> Ah! That's an alright tradeoff. I didn't actually know that you
>> could set the .ptr and .funcptr properties of delegates; I thought
>> they were read-only! Cool.
>>
>
> I didn't know this either... and it opens some ideas up to me... Like,
> perhaps one could do the following:
>
> # class Foo {
> # void bar () { ... }
> # }
> #
> # Foo[] list = ... ;
> # auto dg = &list[0].bar;
> # dg();
> # foreach (x; list[1 .. $]) {
> # dg.ptr = x;
> # dg();
> # }
>
> Might actually be slightly cheaper than a normal call in some cases,
> particularly of Foo and/or bar() are final. Will have to test it...
>
> -- Chris Nicholson-Sauls
Well, I tested it. And the results are... pretty neutral, really. Which is a plus in its
own right, because it does at least mean one can use this trick without worry. Some
exemplar output from the test program:
Repeats: 100
Iterations: 1000
List size: 500
Virtual call: 0 sec / 20 msec / 21417 usec
Manipulated delegate: 0 sec / 18 msec / 19367 usec
Repeats: 100
Iterations: 5000
List size: 500
Virtual call: 0 sec / 86 msec / 87139 usec
Manipulated delegate: 0 sec / 86 msec / 86640 usec
Repeats: 100
Iterations: 5000
List size: 25
Virtual call: 0 sec / 7 msec / 8117 usec
Manipulated delegate: 0 sec / 6 msec / 6901 usec
So, yes, there is occasionally some speedup from using the manipulated delegate, but its
nothing to scream about. And it appears that, as the size of the data increases, or the
number of iterations over it, the times start to drift toward each other and even out.
("Repeats" in the output is the number of times the test was run, with the results being
averaged out.)
-- Chris Nicholson-Sauls
More information about the Digitalmars-d-announce
mailing list