my c++ d c# benchmark!

Started by
70 comments, last by Raghar 17 years, 6 months ago
Quote:Original post by Promit
Presumably, one is only allowed to use the exact implementation originally written in C, without taking into account the fact that a good C implementation may be a terrible implementation for another language.


You seem to be right. I've only just noticed that the version advertised as C++ isn't C++, but is in fact C.
Advertisement
Quote:Original post by Kambiz
I'm just surprised a little: I thought that D shouldn't be much slower than c++ and I thought that c# would be much faster. Maybe there is some optimization option I have not used(?)
What do you think about the results?
Interesting, but you're comparing the Microsoft C++ optimizer with the Digital Mars C++ optimizer. DMD, the Digital Mars D compiler, is built using the Digital Mars C++ optimizer.

To compare apples-apples, it makes sense to compare DMD versus DMC++, or GDC versus g++, as then the optimizer and code generator would be the same for each language. I tried DMD and DMC++, and got essentially the same times for each.



I actually have a suspicion that some of the modifications I applied in the C# version will improve the D version's performance as well. Anyone want to try my edits on D and see what happens? I really don't feel like downloading DMD.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Quote:Original post by Kambiz
d : 26 seconds to compute pi with a precision of 10000 digits.
c# : 34,745(34.745) seconds to compute pi with a precision of 10000 digits.
c++ : 15 seconds to compute pi with a precision of 10000 digits.
...
I do not want to start a language war...

Yeah, right. The fact that you only gave a decimal point only for the C# version (using a comma to represent it, making it look like a huge number) and your dismissal of Promit's benchmark implies that you hold a certain prejudice toward C#. Now, theres nothing inherently wrong with that but trying to spread propaganda in the form of a benchmark is pretty sad if you ask me.
I'll make it fair barakus.

d : 26 seconds to compute pi with a precision of 10000 digits.
c# : 35 seconds to compute pi with a precision of 10000 digits.
c++ : 15 seconds to compute pi with a precision of 10000 digits.

As for propaganda, I see none - just the results of a benchmark.

i don't want to comment on the benchmark a lot. quite frankly these kind of performance benchmarks don't mean so much, but yes they can be interesting in some cases. a pure number crunching benchmark should be winnable by a native language like c++, no surprise there. a realistic number cruncher would resort to simd instructions anyways which (for now) leaves all other alternatives far behind.. but that's only a matter of time (for me that is the main reason not to use managed languages for these kinds of applications. i need the simd capabilities the metal offers).
i like the fact, though, that people are starting to defend c# like most of us here do with c++ and the sc++l. that kind of advocacy for a certain language is a very good sign for the language (and - admit it! - its creators). i think that on its own is a good process.

cheers,
simon
Quote:Original post by barakus
Yeah, right. The fact that you only gave a decimal point only for the C# version (using a comma to represent it, making it look like a huge number) [...] implies that you hold a certain prejudice toward C#.
I think you're reading too much to that. In Europe (where he's from), believe it or not, people use comma to separate decimals (mind-boggling, I know!). And that only C# version had decimals is likely due to the fact that in C# he had to write the outputting code slightly differently. The C-version's timing and output is more of a direct port from the original D code (using the same printf statement).
Quote:your dismissal of Promit's benchmark
I think this was fair. It's not like Promit's code is more idiomatic C#, it's just a tweak that happens to make .NET run faster. Similar tweaks could probably be found in C++ and D versions as well, and we could spend weeks optimizing each one. Why not actually compare versions that are near identical in code to save the trouble? It even looks to me like his code would make the algorithm wrong due to the fact that floating point math isn't as accurate, but I didn't check this..
I've deleted the AP replies that seem intent on derailing this thread. So far the discussion is clean and interesting - whilst these benchmarks may not be the best way to compare languages they are a good platform for learning and discussing various characteristics.

The whole "," or "." thing is a bit pointless - why bother arguing over something so silly [smile]

Cheers,
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

I'm not much of a .net freak but to me it seems like .net is going to be slower no matter what in this specific case. It's basically a series of tight loops with bounds checked array accesses which will generate at least an extra branch for each array access, probably with stack unwinding also.

I see nothing wrong with the test and it demonstrates what is a fairly well known weakness of .net, tight loops and a lot of array accesses.
Quote:Original post by Anonymous Poster
It's not like Promit's code is more idiomatic C#, it's just a tweak that happens to make .NET run faster. Similar tweaks could probably be found in C++ and D versions as well, and we could spend weeks optimizing each one. Why not actually compare versions that are near identical in code to save the trouble? It even looks to me like his code would make the algorithm wrong due to the fact that floating point math isn't as accurate, but I didn't check this..


Different languages work in different ways. It is extremely biased to write a program in one language (C++) and expect a direct port to run equally fast on other languages (D or C#, in this case). Spending "weeks" (hopefully less) on optimizing each language according to their strengths would provide the best benchmarks. After all, I could care less how well C# or D implements C-specific algorithms. What I care about is the performance I'll achieve using those languages in the way they're designed.

- Mike

This topic is closed to new replies.

Advertisement