RFC on range design for D2

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Sep 10 07:49:56 PDT 2008


bearophile wrote:
> Andrei Alexandrescu:
>> That's odd. The array appender should never, by definition, do 
>> significantly worse than the straight array append.
> 
> But the reality of your code and benchmarks may differ from the
> abstract definition :-)

But it's not abstract, and besides my benchmarks do support my
hypothesis. On the common path my code does the minimum amount that any
append would do: test, assign at index, bump. On the less common path
(invoked an amortized constant number of times) my code does an actual
built-in append plus a call to capacity to cache it. Assuming the
built-in array does a screaming fast append, my code should be just
about as fast, probably insignificantly slower because of the extra
straggler operations.

>> I think some other factor intervened (e.g. swapping). Also don't
>> forget to compile with -O -release -inline and to test several
>> times after a warmup run.
> 
> I have kept an eye on such things too. Note that benchmarks are
> generally tricky.
> 
> I am using DMD v1.035, on a Core Duo 2 GHz, 2 GB RAM, on Win, the
> code doesn't make HD swap, and timings are warm. My timings are
> repeatable within 0.02-0.03 seconds on my PC. If you want I can give
> you the whole testing code, of course. But it's just the builders.d
> module of my libs plus the added testing code I have shown you.

But I copied your test code from your post. Then I adapted it to Phobos
(replaced putr with writefln, clock with ctime and the such, which
shouldn't matter). Then I ran it under Phobos. For the built-in array
append we get comparable numbers. So there must be something that makes
your numbers for ArrayAppender skewed. I'm saying yours and not mine
because mine are in line with expectations and yours aren't.


Andrei



More information about the Digitalmars-d-announce mailing list