C# and C++

Page 2 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
It's impossible to construct meaningful and relevant test cases. You can construct some meaningful test cases, but then they are too small to be relevant (who cares which language is faster at closing a text file?). Or you can make them relevant, but then they are too context-specific to be meaningful (who is going to write a GC layer for C++ so we can test performance?)

The question is not whether the C++ program will have to execute fewer x86 instructions to get something done: it will. So there you go. C will exec even fewer still, and assembler the fewest of all. The addition of the managed features of .Net languages is an _explicit_ tradeoff of instruction overhead against robustness. Whether it's worth it is not a close call; not even remotely close. In ten years when you write C++ younger devs will think you're adding one to a variable, or you'll be like the guy who posted the fortran question yesterday.

Comparing them specifically as to performance is pretty silly, to be honest. When C++ started becoming relevant I was programming on an 80286 with a meg of ram. Windows XP couldn't exist on that hardware, and C#/.Net couldn't exist on it either. If you want to pick one specific task they both can do, then I bet DOS 6.0 will be way faster than XP on my dual-core AMD machine with 2.2 Ghz clocks and 2 gigs.
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Originally posted by: JACKDRUID
Originally posted by: Crusty
, just because a program loads faster does not mean that it is always faster.. which goes to my first post about your generalization.

whats the difference between a C# binary vs C++ binary?...nothing.. they are all binaries.. if one loads faster, its faster.

That has nothing do with one being written in C# or C++.... you are invalidating your own logic with every new post.

You stated that C++ is always faster then C#, and I'm arguing that it isn't. It's simple, there is no way any person or any machine could ever determine that for every single possible combination of code. Always is absolute, and is most definitely not true.


 

JACKDRUID

Senior member
Nov 28, 2007
729
0
0
Originally posted by: Crusty
Originally posted by: JACKDRUID
Originally posted by: Crusty
, just because a program loads faster does not mean that it is always faster.. which goes to my first post about your generalization.

whats the difference between a C# binary vs C++ binary?...nothing.. they are all binaries.. if one loads faster, its faster.

That has nothing do with one being written in C# or C++.... you are invalidating your own logic with every new post.

You stated that C++ is always faster then C#, and I'm arguing that it isn't. It's simple, there is no way any person or any machine could ever determine that for every single possible combination of code. Always is absolute, and is most definitely not true.

For god sake, as stated by Markbnj, its a trade-off

will the extra JIT compilation take time? YES
is it worth it? YEES x 10000

I'm done.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Originally posted by: JACKDRUID
Originally posted by: Crusty
Originally posted by: JACKDRUID
Originally posted by: Crusty
, just because a program loads faster does not mean that it is always faster.. which goes to my first post about your generalization.

whats the difference between a C# binary vs C++ binary?...nothing.. they are all binaries.. if one loads faster, its faster.

That has nothing do with one being written in C# or C++.... you are invalidating your own logic with every new post.

You stated that C++ is always faster then C#, and I'm arguing that it isn't. It's simple, there is no way any person or any machine could ever determine that for every single possible combination of code. Always is absolute, and is most definitely not true.

For god sake, as stated by Markbnj, its a trade-off

will the extra JIT compilation take time? YES
is it worth it? YEES x 10000

I'm done.

Yeah, you guys are debating semantics at this point. I'm quite sure you're both right, but are viewing it from different perspectives.
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Mwa ha ha! Here I come to stir up this hornet's nest even more!
<rant>
ALL CODE SHOULD BE WRITTEN IN RAW ASSEMBLY OR ELSE YOU ARE A NOOB! etc., etc., etc.,
</rant>

Ok, in all seriousness, C#'s programmability features far outweigh C++'s potential speed. Since program execution time is seldom relevant, nearly everyone should stay in the happy-go-lucky world of C# and let MSmagic handle the nastiness for you. But, as per my previous argument of C++ v. Java 2008, there is always a way to do it faster in C++. Even if C# JITs to the same code as C++, there is still the JIT overhead. Finite, nonzero overhead. 1 / x > 1 / ( x + delta ) for delta > 0.

Edit: Found this link in another part of the forums (I changed the link text to my impression of the doc): C# v. C++ from 10,000 feet
 

Verdant

Member
May 8, 2003
83
0
0
quick nit-picky things: MSIL is officially CIL, it was never actually released as MSIL
CIL code can run on the cross-platform mono-project (http://www.mono-project.com/Main_Page) while the platforms differ in that the microsoft namespace is much different... it is much easier to port between .net and mono code than c++ for a pc/mac/etc.... and you can obviously just write mono compliant code in the first place.

To understand the answer to "which is faster?" you have to realize the question is fundamentally flawed.

All code that runs on a computer is in the form of basic operations, which can be programmed directly with an assembly language (or you could write the binary if you REALLY wanted to)

All programs will essentially run on this set of instructions, writing in one language over another does not technically add any functionality, however, typically the higher level a language is, the more abstracted and more pre-written functionality is provides the developer with.

This makes it easier to program, but in the end, the code has to be reduced to object code, and for every layer of abstraction the compiler/runtime environment has to "intelligently" translate the instructions down, some "x%" of optimization is not attained.

So the higher level, the more potential for non-optimal code to running, so if you coded an application (to do the same thing) 100% perfectly in assembly, c/c++, c#; assembly would potentially the fastest, etc.

The real issue with this is that time is a scarce resource, and no one is a "perfect" programmer, as platforms and languages abstract the cpu more, it "does more" for you, which means there is less potential for error which might cause the program to run slower...

And so you must choose the appropriate platform for the situation, in addendum, as computers achieve more and more compute power this "last mile" of optimization is minimized


So, the higher level computer instructions are:
cons:
- potential speed
pros:
+ development time
+ error handling
+ ease
+ maintain-ability

so to answer the question "which is faster?"
i respond: how much time do you have?

Personally I use the highest level platform i can get away with that will meet the requirements of the project.
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Originally posted by: Verdant
Personally I use the highest level platform i can get away with that will meet the requirements of the project.

A+.

 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Why would he have done that on purpose? Is 'Kateland' some sort of insult I haven't heard of? Most likely he typed it in by hand and simply didn't spell it right.
 

Kyteland

Diamond Member
Dec 30, 2002
5,747
1
81
Originally posted by: Markbnj
Why would he have done that on purpose? Is 'Kateland' some sort of insult I haven't heard of? Most likely he typed it in by hand and simply didn't spell it right.
The Quote option fills it in for you, and he "got it right" in his other posts. Maybe I'm overreacting.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Yeah, maybe a little, but we've all been there. . The quote option does fill it in for you, but from time to time I just type in the tags. Actually I do that a lot more than I use the quote option.
 

hans007

Lifer
Feb 1, 2000
20,212
18
81
Originally posted by: Crusty
Originally posted by: JACKDRUID

C# is not compiled to be read directly by your CPU/os. It is compile to msil (.net version of aseembly language) to be read and executed by .net framwork.

C++ on the other hand, is compiled to be read directly by the CPU/os. so C# will always be slower than C++ in term of speed.

That's a bad generalization. Yes, there is extra overhead and in most cases the exact same code will be faster in C++ then in C#, but not always. It totally depends on the environment and applications.

C++ will be faster almost all the time. i doubt itll be a noticeable difference for say UI based things. I.e. things blocking anyway

I believe C# can be compiled directly to native code if you set some switches . I mostly code in C/c++ so I am not exactly sure where that switch is, but its supposed to be there.
 

tuteja1986

Diamond Member
Jun 1, 2005
3,676
0
0
Learn C# ... you will understand Object Oriented programming faster. Remember C# don't have global variable or function or even emphasis the use of pointers.

 

imported_Dhaval00

Senior member
Jul 23, 2004
573
0
0
Originally posted by: tuteja1986
Remember C# don't have global variable or function or even emphasis the use of pointers.

What do you mean by "C# don't have global variable or function?" I really hope you didn't mean that...
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Originally posted by: Dhaval00
Originally posted by: tuteja1986
Remember C# don't have global variable or function or even emphasis the use of pointers.

What do you mean by "C# don't have global variable or function?" I really hope you didn't mean that...

I'm sure the poster means that all functions, fields, properties, etc., have to be declared at class scope at a minimum.

I'm not sure any language since BASIC has had real global-scope variables; just ways you could screw yourself if you really wanted to.
 

gsellis

Diamond Member
Dec 4, 2003
6,061
0
0
The second time they both run, it will be about the same ....

(dynamic libs still in system, jit loaded and primed)
 

tuteja1986

Diamond Member
Jun 1, 2005
3,676
0
0
Originally posted by: Markbnj
Originally posted by: Dhaval00
Originally posted by: tuteja1986
Remember C# don't have global variable or function or even emphasis the use of pointers.

What do you mean by "C# don't have global variable or function?" I really hope you didn't mean that...

I'm sure the poster means that all functions, fields, properties, etc., have to be declared at class scope at a minimum.

I'm not sure any language since BASIC has had real global-scope variables; just ways you could screw yourself if you really wanted to.

yup ... When was learning C++ , i used global variable ;( ... then my professor was like "ERR..." and told me never to use them again.
 

gsellis

Diamond Member
Dec 4, 2003
6,061
0
0
Merry1987 post is spam. PM'ed the AT mod already

Taken care of, thanks gsellis - Markbnj, Programming mod
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |