Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I need high performance. Will there be a difference if I use C or C++?

I need to write a program (a project for university) that solves (approx) an NP-hard problem. It is a variation of Linear ordering problems. In general, I will have very large inputs (as Graphs) and will try to find the best solution (based on a function that will 'rate' each solution)

Will there be a difference if I write this in C-style code (one main, and functions) or build a Solver class, create an instance and invoke a 'run' method from a main (similar to Java)

Also, there will be alot of floating point math going on in each iteration.

Thanks!

like image 411
Itsik Avatar asked Nov 17 '09 18:11

Itsik


People also ask

Is C or C faster?

C++ language is an object-oriented programming language, and it supports some important features like Polymorphism, Abstract Data Types, Encapsulation, etc. Since it supports object-orientation, speed is faster compared to the C language.

Is C Sharp faster than C?

Still, my conclusion is that C# is not as fast as C++ in most cases by default. But I think it's not much slower and it usually doesn't matter. When you do have performance-sensitive code, you can optimize C# and achieve near-similar performance to C++.

Should I use C or CPP?

Compared to C, C++ has significantly more libraries and functions to use. If you're working with complex software, C++ is a better fit because you have more libraries to rely on. Thinking practically, having knowledge of C++ is often a requirement for a variety of programming roles.


2 Answers

No.

The biggest performance gains/flaws will be on the algorithm you implement, and how much unneeded work you perform (Unneeded work could be everything from recalculating a previous value that could have been cached, to using too many malloc/free's vs using memory pools, passing large immutable data by value instead of reference)

like image 76
nos Avatar answered Oct 02 '22 17:10

nos


The biggest roadblock to optimal code is no longer the language (for properly compiled languages), but rather the programmer.

like image 31
Reverend Gonzo Avatar answered Oct 02 '22 18:10

Reverend Gonzo