Click here to Skip to main content
15,908,173 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
KesavanandChavali2-Feb-16 20:51
KesavanandChavali2-Feb-16 20:51 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
irneb2-Feb-16 21:55
irneb2-Feb-16 21:55 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
Jonas Hammarberg2-Feb-16 23:17
professionalJonas Hammarberg2-Feb-16 23:17 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
amagitech3-Feb-16 0:02
amagitech3-Feb-16 0:02 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
Thornik3-Feb-16 0:48
Thornik3-Feb-16 0:48 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
amagitech3-Feb-16 1:01
amagitech3-Feb-16 1:01 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
loctrice3-Feb-16 2:59
professionalloctrice3-Feb-16 2:59 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
hal23x3-Feb-16 6:42
professionalhal23x3-Feb-16 6:42 
I copied and pasted your exact code and compiled them with the Visual Studio 2008 (v9.0) compilers (cl for C++, csc for C#) and got wildly different results--C++ reported a time of 2.868 seconds, versus 4 for C#. My exact command lines were:

For C++:
cl /EHcs cpptest.cpp

cpptest.exe > cppoutput.txt


For C#:
csc cstest.cs

cstest.exe > csoutput.txt


As far as why people say C++ is faster than C#--there are a great many factors, including how the code was written, what the code is doing, how it was compiled, the system (hardware and OS) it's run on, compilers, etc. that can make a difference, and no doubt there may be examples of C# performing some things faster in some instances. In general, I think it has more to do with the overhead inherent in C#, but that's just me speculating. Maybe we can get a real answer from someone knows more than I do about the internals of the languages (and whether managed C++/CLI would have had results similar to the C# code above).
GeneralRe: Everyone says c++ is faster than c#, why? Pin
Sharath Shetty3-Feb-16 6:47
Sharath Shetty3-Feb-16 6:47 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
Member 120239883-Feb-16 9:22
Member 120239883-Feb-16 9:22 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
Member 120239883-Feb-16 9:27
Member 120239883-Feb-16 9:27 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
sbcLion3-Feb-16 16:42
sbcLion3-Feb-16 16:42 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
Member 82246963-Feb-16 21:40
Member 82246963-Feb-16 21:40 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
jschell6-Feb-16 12:53
jschell6-Feb-16 12:53 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
zezba90006-Feb-16 16:00
zezba90006-Feb-16 16:00 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
pdohara10-Feb-16 3:58
pdohara10-Feb-16 3:58 
RantElephant. Sunshine. Telerik. Pin
Kornfeld Eliyahu Peter2-Feb-16 0:54
professionalKornfeld Eliyahu Peter2-Feb-16 0:54 
GeneralRe: Elephant. Sunshine. Telerik. Pin
OriginalGriff2-Feb-16 1:00
mveOriginalGriff2-Feb-16 1:00 
GeneralRe: Elephant. Sunshine. Telerik. Pin
F-ES Sitecore2-Feb-16 1:03
professionalF-ES Sitecore2-Feb-16 1:03 
GeneralRe: Elephant. Sunshine. Telerik. Pin
Kornfeld Eliyahu Peter2-Feb-16 1:08
professionalKornfeld Eliyahu Peter2-Feb-16 1:08 
GeneralRe: Elephant. Sunshine. Telerik. Pin
Jörgen Andersson2-Feb-16 2:29
professionalJörgen Andersson2-Feb-16 2:29 
JokeRe: Elephant. Sunshine. Telerik. Pin
Richard Deeming2-Feb-16 3:48
mveRichard Deeming2-Feb-16 3:48 
GeneralRe: Elephant. Sunshine. Telerik. Pin
Slacker0072-Feb-16 3:38
professionalSlacker0072-Feb-16 3:38 
GeneralRe: Elephant. Sunshine. Telerik. Pin
Dave Kreskowiak2-Feb-16 5:37
mveDave Kreskowiak2-Feb-16 5:37 
GeneralRe: Elephant. Sunshine. Telerik. Pin
Mycroft Holmes2-Feb-16 14:14
professionalMycroft Holmes2-Feb-16 14:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.