Appender is ... slow
Jonathan M Davis via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Aug 14 12:43:13 PDT 2014
On Thursday, 14 August 2014 at 19:29:28 UTC, Philippe Sigaud via
Digitalmars-d-learn wrote:
>> It sounds like you're trying to use it as a way to manage
>> reusing
>> the array, and I have no idea how it works for that.
>
> There is a misunderstanding there: I'm using clear only to
> flush the
> state at the beginning of the computation. The Appender is a
> class
> field, used by the class methods to calculate. If I do not
> clear it at
> the beginning of the methods, I keep appending new results to
> old
> computations, which is not what I want. But really, calling
> clear is a
> minor point: I'm interested in Appender's effect on *one* (long,
> concatenation-intensive) computation.
Then it sounds like you're reusing the Appender. I've never done
that. In fact, I would have assumed that that would mean that you
were attempted to fill in the same array again, and I wouldn't
have even thought that that was safe, because I would have
assumed that Appnder used assumeSafeAppend, which would mean that
reusing the Appender would be highly unsafe unless you weren't
using the array that you got from it anymore.
I always use Appender to construct an array, and then I get rid
of the Appender. I don't think that I've ever had a member
variable which was an Appender. I only ever use it for local
variables or function arguments.
>> I've
>> never actually benchmarked it for just creating arrays via
>> appending. I'd
>> just assumed that it was faster than just using ~=, because
>> that's what it's
>> supposedly for. But maybe I just completely misunderstood what
>> the point of
>> Appender was.
>
> I don't know. People here keep telling newcomers to use it, but
> I'm
> not convinced by its results. Maybe I'm seeing worse results
> because
> my arrays are do not have millions of elements and Appender
> shines for
> long arrays?
I have no idea. It was my understandnig that it was faster to
create an array via appending using Appender than ~=, but I've
never benchmarked it or actually looked into how it works. It's
quite possible that while it's _supposed_ to be faster, it's
actually flawed somehow and is actually slower, and no one has
noticed previously, simply assuming that it was faster because
it's supposed to be.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list