On 06/19/2017 07:42 PM, SrMordred wrote:
I was playing around my ES and different ways of doing it with D.
I end up with a performance test of alias func vs ranges vs opApply.
code here:
https://dpaste.dzfl.pl/a2eff240552f
Results on my machine win 10 x64, compiling with:
dub run --build=release --arch=x86 --compiler=ldc2
(unable to test with gdc because
https://forum.dlang.org/thread/bfmbvxtnqfhhgquay...@forum.dlang.org)
Alias func: ~40ms
Range Type(front, popFront, emtpy): ~50ms
OpApply: ~25ms
So first, if I make some really dumb relate to profiling speed or any D
code let me know!
1) I thought that ranges were the fastest, but it got the least
performant code.
I don't think ranges are expected to be faster than the others.
2) opApply was faster than alias func. Its suprising for me.
For me, alias_fun and op_apply are very close. If anything, alias_fun
seems to be slightly faster.
Typical output (ldc2 -release -O3):
----
36
Result(51)
44
Result(88)
37
Result(-127)
----
3) Not possible to return multiple values. So in the front() method I
Wrapped a node of pointers.(maybe a performance impact here?, there is a
better way of doing it? )
Avoiding bounds checking makes it faster for me (but is unsafe of course):
----
return Node(&values.ptr[index_[0]], &results.ptr[index_[1]]);
----
Typical timing:
----
37
Result(74)
39
Result(113)
38
Result(-1)
----
Almost there, but still a bit slower than the others.
By the way, if I read it right, indexes is just `0 .. limit`, twice,
isn't it? So there's no real point to it in the sample code. When I get
rid of indexes and just count up to `limit`, all three versions perform
the same. But I guess you're going to have arbitrary values in indexes
when you actually use it.
4) there are no equivalent of declaring Type& x; (ref type) right?
Right. ref is only for parameters and returns. For variables, you have
to user pointers.