std.container.RedBlackTree versus C++ std::set

Dmitry Olshansky dmitry.olsh at gmail.com
Thu Feb 14 06:37:40 PST 2013


14-Feb-2013 03:22, Ivan Kazmenko пишет:
> Hi!
>
> I'm learning to use D collections properly, and I'm looking for a sorted
> data structure with logarithmic access time (i.e., a binary search tree
> will do, but a hash table would not help). As far as I can see,
> std.container.RedBlackTree is exactly what I need. However, I am not
> sure if I use it as intended as its performance seems inferior to a C++
> STL solution (e.g., std::set).
>
> To be more specific, right now I wonder what is the best (or intended)
> way to store an object in the RedBlackTree: should it be a class
> reference, or a struct (passed by value), or something quirkier like an
> integer pointing into an array or a simple pointer. The rest of my
> program suggested to use structs, but the whole thing turned out to be
> rather slow, and the profiler told me that these structs are being
> copied around much more than I anticipated.
>
> And so I wrote a minimalistic test program to check the number of copy
> (postblit) constructor calls. Here is the D version:

[snip]

>
> And the results are:
> D2 (DMD 2.059, -O):             11,389,556

I'd add :

-release -inline

or it may not inline away temporary copies.



-- 
Dmitry Olshansky


More information about the Digitalmars-d-learn mailing list