|
Shall we cut that in half and say it's a programming discussion, or a technical question, then?
I'm not sure that fits here, anyway.
You always obtain more by being rather polite and armed than polite only.
|
|
|
|
|
You sound like a liberal.
On and you're wrong. It's simply a technical discussion.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
So liberals are not permitted here. I'm not a liberal, but I'm sure that sooner or later I'll say something that is not extreme right wing enough to satisfy you.
|
|
|
|
|
Ygnaiih wrote: So liberals are not permitted here. Only a liberal would have made that leap.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Told you up front I'm not a liberal. My point is if you want to do a political discussion, code project is not the place for it.
|
|
|
|
|
Ygnaiih wrote: Told you up front I'm not a liberal Ya, I was making a silly joke.
Ygnaiih wrote: if you want to do a political discussion, code project is not the place for it. Actually, it is, but not in the Lounge. The Soapbox is the place for it.
However, John wasn't making any political statements.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I'll Trump yours and give you a bit of Sanders.
|
|
|
|
|
Agreed
Jeremy Falcon
|
|
|
|
|
Are we that picky now that we cannot even talk about programming language performance in the Lounge ?
If that is the case, then we should rename the site LoungeProject.com ...
I'd rather be phishing!
|
|
|
|
|
After a quick check, what you're really comparing here is the efficiency of Console.WriteLine vs cout
If you swap cout for printf you get much more similar times. In my case the C++ was a second faster than the C# but it's not a very fair comparison.
Really I don't think you'll find much difference in performance of either.
|
|
|
|
|
Good catch!
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Exactly. To make a fair comparison, just eliminate all io within the loop. Or, better yet, don't do any io within the code block that is measured.
That said, I wouldn't expect *any* meaningful difference for this code. it's just basic arithmetic that translates directly to assembly, and that goes for both C++ and C#.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
An answer to the question? What's wrong with you!!!
It's funny how it was so horrible that this question was here, but the whole long conversation about liberals and stuff is just fine! Hmmm people just being people again. It's a shame the way we act sometimes.
hatfok
King Yiddum's Castle
Pegasus Galaxy
|
|
|
|
|
Yes, it's comparing Console.WriteLine with cout, but even then it's not a fair comparison. std::endl doesn't just write a newline character, it also flushes the output buffer. Try replacing endl with '\n'.
Also try redirecting the console output to a file, running each program several times, discarding the outliers and taking an average of the remaining run times then come back with your results. I doubt that there will be much difference between the two programs because basic C++ streams are not as bad as some people here are trying to make out.
|
|
|
|
|
Thanks for getting back on topic. While questioning c++ is perhaps not PC, it is relevant to programmers (given the marked difference in development time.)
|
|
|
|
|
Well... you know now how much of a lie it is!
Arguably, theoretically, C++ should be faster because it has a better ahead of time compiler.
But it's also relying on harder to optimize and write library and less elegant compiler constructs... which make it slower...
However C# will slow down at 2 crucial point:
- Start-up. C# start-up time is definitely, humanely perceptibly, slower (because of all the assemblies verification)
- Allegedly real time code can only be reliably be written in C++ as it is, likely easier to write allocation free code, whereas realtime C# slow down on hidden object allocation (although its allocation algorithm are much faster than C++ ones)
- Finally, for laugh, it's just an empty arguments that C++ developer have against C# developer. Surprisingly most of the random comparison code written by random developer make C# wins. But the occasional C++ zealots sometimes come back after a couple of day of profiling and disassembly with a marginally faster C++ version saying that the C++ version was... unoptimized! So... here you have it!
|
|
|
|
|
That's the way I see it. C++ as a religious belief
|
|
|
|
|
I'm not an expert in this but I can tell you this much:
- You didn't set a processor affinity. Stack swaps could have skewed your results.
- You didn't set the process and thread priority to high. Your programs code have been interrupted by other threads.
- Did you make sure you ran both programs with compiler optimization and without debugger/profiler attached?
- Integer-arithmetic isn't representative for the overall speed of the language.
Take a look here: Head-to-head benchmark: C++ vs .NET[^]
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
That article provides a rather thorough comparison, but it focuses on library implementations, not the core language. Just from skimming over the results I spotted several remarks on 'lousy' implementations, and that alone is a dead giveaway that the results should be taken with a huge pint of salt.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Thanks for the very informative link!
|
|
|
|
|
3rd point down is crucial. Newbies often forget to ramp up compiler optimisation to -O2 or -O3. Leaving it as the default optimisation level usually sucks.
|
|
|
|
|
You successfully proofed the poor performance of C++ streams.
Just try the C++ version with printf instead of streams and it should be faster.
|
|
|
|
|
Yee I tried printf("%i\n",i);
it is 7 second. That's faster than coutt
|
|
|
|
|
Others have already nailed it down to C++ streams. Besides that I remember reading somewhere that the execution on modern highly parallelized systems also highly depends on the structure of the code.
For example: modern systems would read several machine instructions ahead and analyze them while executing the current one. So if your code would have multiple jump instructions which would prevent effective pipelining this would probably run slower.
Note that I'm not 100% practically sure of what I just wrote. It's theoretical.
|
|
|
|
|
Tomaž Štih wrote: I'm not 100% practically sure of what I just wrote. I'd suggest that as a signature for some of our regular Lounge participants. I won't name names.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|