benchmark on binary trees

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Dec 4 15:23:37 PST 2015


On 04.12.2015 21:30, Alex wrote:
> Yes, I missed this, sorry. The main part of the question was probably
> about the class and struct difference. I thought handling with structs
> and pointers would be faster then with classes.

When you use a struct directly, without going through a pointer, that 
can be significantly faster than using a class. But structs through 
pointers are pretty much the same as classes, performance-wise.

[...]
> Why the parallel version is slower then the sequential?
> If you set
> int n = 14 in the main function
> the parallel version is MUCH slower then the sequential. At my machine
> 7x slower. Shouldn't it be the other way round?

I don't know what's going on here. You're allocating a lot of 
`TreeNode`s, though. That's probably not very parallelizable. The GC 
could also play a role.

[...]
> As ldc doesn't have the experimental part of the includes, compared on
> the first version. The result was: program compiled with ldc2, same
> params, was 5% slower... nothing crucial, I think...

"The experimental part" is std.experimental.allocator, right? I may be 
wrong here, but I think the default allocator is essentially just `new`. 
So that wouldn't give you any performance boost.

[...]
> Yeah... so the answer here for me, is that I can stay with my way of
> thinking in c# style. :)

In this case, I think you're fine. Generally, be aware that D doesn't 
shine when you create lots of throw-away objects. The GC can't compete 
with those of C# or Java, so when you translate code from those 
languages too closely, performance may be worse.


More information about the Digitalmars-d-learn mailing list