Short article on std.parallism

Jonathan M Davis jmdavisProg at gmx.com
Mon May 30 22:59:48 PDT 2011


On 2011-05-30 22:52, Andrej Mitrovic wrote:
> On 5/30/11, Vladimir Panteleev <vladimir at thecybershadow.net> wrote:
> > On Mon, 30 May 2011 04:18:14 +0300, Jeremy Wright
> > <jeremy at codestrokes.com>
> > 
> > wrote:
> >> I implemented bucket sort in D to demonstrate how easy it is to use
> >> std.parallelism.  I welcome any feedback.
> > 
> > One thing: I would suggest to avoid using ~= in a tight loop, as it is
> > rather slow. Using std.array.appender for the first loop and
> > std.array.join for the second one should be much faster.
> > 
> > --
> > Best regards,
> > 
> >   Vladimir                            mailto:vladimir at thecybershadow.net
> 
> I wonder why we even have this operator in the language if we're
> supposed to avoid it all the time.

There's no problem with using it, generally-speaking. And it's actually faster 
than it used to be, so it's less of an issue. The problem really only lines 
with a tight loop. Extra checks have to be made with ~= to verify that 
reallocation isn't needed which don't have to be made with Appender, because 
it's able to make assumptions that ~= can't make. So, if you're in a loop that 
appends over and over for a large number of iterations, it's going to be 
faster to use Appender. Other than that, ~= is plenty fast enough.

- Jonathan M Davis


More information about the Digitalmars-d-announce mailing list