Question:
C++ vs C# programming question?
anonymous
2012-03-05 13:17:57 UTC
I'm a novice programmer and I'm wondering why...

for (int i = 0; i < 1000000000; ++i)
{
for (int j = 0; j < 1000000000; ++j)
{
for (int x = 0; x < 1000000000; ++x) ;
}
}

... takes over 10 minutes with C# and less than a second in C++?

I compiled the same code in the same compiler both set to release, so why such a massive performance difference? I understand C# is managed but that's a huge difference.


Thanks
Three answers:
Jared
2012-03-05 13:50:26 UTC
Are you sure that the c++ compiler didn't locate the empty loops and remove them? I mean some compilers will find this and remove them. I just ran this case and it is taking awhile using the standard GNU C++ compiler (g++). I will try VS tonight since I have no windows OS until I get home. I'm pretty sure that it's noticing the first loop is empty, removes it, second loop is now empty, removes it, third loop is now empty, removes it...still going for 2 minutes now.
?
2016-10-15 11:01:01 UTC
i'm a gnu/linux c/c++ programmer too. i've got faith you may properly known in basic terms some straight forward stuffs in C to in basic terms get the info without postpone. and then go into c++. no count in case you like it or not you may properly known some staple products of C. each and all of the excellent.
anonymous
2012-03-05 13:22:26 UTC
Because C++ is a lot lower and hell of a more efficient programming language...C# is very object based and inefficient so to speak.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...