adisharma

Is C or C++ faster?

Recommended Posts

Hello Everyone, I am a new one in this forum and want to know Is C or C++ faster. Which is easy to understand and goes with the scope in the present scenario.

Share this post


Link to post
Share on other sites

You should maybe give more background. Otherwise the answers will be only as good as your question.
C is faster because...
C++ is faster because...

Share this post


Link to post
Share on other sites
Posted (edited)
On 6/3/2019 at 2:40 AM, adisharma said:

Is C or C++ faster

Oh my, I've trying to keep myself from posting to this question for a while now and just failed to resist.

The only purpose for asking such a question without context is to gender ill-will with your pals while having beers at a bar. [OK, it might also be a test question to see if you've been attending classes... shame on your professor] The following commentary might be a bit more useful.

I suppose that you really want to know if you should choose learning one over the other to create an application that has a higher performance. This question, while a bit more defined is not all that much better at stating a context. It depends on the application, it depends on the target, it depends on the compiler, it depends on the optimization choices, it depends on the third party libraries that your application uses, it depends you how you implement your algorithm, it depends on your skill at understanding the algorithm and your language of choice, it depends on what you've had to eat in the last 12 hours, it depends on what time it is when you write your code,  etc, etc. It depends on what you mean by faster. Do you mean faster time to develop a robust application? Do you mean faster time time to execute one particular algorithm on the same hardware? Do you mean faster time to execute all code on the same hardware?

Just for the sake of argument, let's assume that C generally results in faster code execution times for a particular application on particular hardware that doesn't use any third party libraries. Would you think that you can't write poor code in C that performs slower than better code in C++? Is executing a particular algorithm in 25 us better than executing it in 24us? Maybe. Probably not. Do thou think that being expert in one language will make all of your work so much faster than if you chose the other a marketable feature? I wouldn't bet on it. Besides, usually customers want something that works reliably and accomplishes something rather than runs really fast and sometimes accomplishes a task.

Here's my answer and I bet that it's true for any context; "It depends".

Back in the days when i386 was a hot microprocessor you could get 'hand-crafted' assembly libraries to perform certain tasks, especially for video ( back before there were GPUs and video was pretty much just buffer ). A lot of the techniques that have made the modern microprocessor faster ( and inherently unsafe ) has rendered spending time crafting such libraries useless. That doesn't mean that you can't add inline C or C++ code to your application if it makes sense. Of course the PC is but one (perhaps I should say one universe of) hardware platforms for which you can write applications. For a PC your 'fast' application might not be so notability fast running on any particular OS.

Edited by zygot

Share this post


Link to post
Share on other sites
9 hours ago, xc6lx45 said:

In the right hands, it's twice as fast

Ok... possibly... probably not to write a driver for Linux on a dual boot Windows/Linux machine... It depends.... C# has worked for me for multi-threaded USB applications in terms of speed. I don't know if you can even write a Windows driver with it. (I gave up trying to write drivers for Winwoes long ago as half of the versions have absolutely no purpose other than to create revenue... vista...m-u-s-t... c-o-n-t-r-o-l... s-e-l-f... The problem is that I write application code so infrequently these days that I never fit into the "right hands" category any more.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now