SITERAW

Is C++ really slower than C?

Author Message
Jaguar # Posted one month ago
Jaguar

Hello everyone,

I'm wondering just how much slower an app written in C++ would be compared to an equivalent app written in C. Creating a thread about it because I'd like to hear as many opinions as possible.

Thanks!

Ads
ParkerW # Posted one month ago
ParkerW

A lot of video games are programmed in C++. That's a good enough answer for me. ;) Not you?

Maul # Posted three weeks ago
Maul

When it comes to video games, the real need for speed is at the display level. And that's mostly handled by middleware (usually DirectX). The middleware talks directly to the hardware, so it's not really the same thing.

ParkerW # Posted two weeks ago
ParkerW

Sure, I agree when it comes to rendering. But you think modern games are just about graphics? Just as an example: the AI in a game isn't handled by the graphics card.

Valter # Posted two weeks ago
Valter

"You think modern games are just about graphics" ...

Yes? Don't know what you mean by games but for your typical AAA, it's 90% graphics, 5% sound (at most), and 5% actual gameplay (AI, data handling, physics engine, etc...). If you think I'm exaggerating with the numbers, I'm really being quite generous.

Phoenix # Posted one week ago
Phoenix

Obviously C is faster. Where do you think the obsession with creating "C but with objects" comes from? Why do you think so much time and energy goes into stuff like Rust? If C++ had, in addition to OOP and better syntax, also higher levels of perf everyone would be using it.

Kegon # Posted yesterday
Kegon

Yooooo... asking that in the C++ forum dawg ... you'll get unbiased answers sure

Jaguar # Posted yesterday
Jaguar

The other alternative was the C Forum lol ^^

Kegon # Posted yesterday
Kegon

C forum, best forum

Giovanni # Posted two hours ago
Giovanni

Faster, slower - that's not really the point. You use the tools that are best suited for your problem. Then you identify bottle necks and optimise them (even with ASM if needed). A software project can involve multiple languages working together, each one used because it's the most appropriate for a specific task.

Jaguar # Posted two hours ago
Jaguar

Funny you mention that. I hit a real snag myself. I'm developing an app that does stats based on data pulled from files. Loading the data takes forever because the files are massive, but that's another story.

The real problem is that I have a whole mess of classes and methods to process the data every which way to display stats, and in some parts, it slows down a lot.

I'm using tons of MFC templates (CList, CArray, etc.), multi-dimensional dynamic arrays, classes that are similar but I can't seem to factor them properly, complex class hierarchies, expensive search and comparison methods, etc... It's pure data handling - no hardware access involved.

I've already optimized my algorithms as much as I could (and honestly had a blast doing it), but now, I'm stuck. I can't see where else I could shave off time or performance losses...

Giovanni # Posted one hour ago
Giovanni

You need to pinpoint exactly which method or methods are eating up the most time, and then you could rewrite them in assembly to take full advantage of modern processor instruction sets (SSE, MMX & co) and parallelisation.

Celeri # Posted one hour ago
Celeri

And how exactly are you supposed to adapt MFC class operations into assembly???

Not so sure it would even be faster - plus doing floating point math in ASM? Good luck. Especially for a stats app. That's easily 6 extra months of development.

Kalvin # Posted 7 minutes ago
Kalvin

But we're getting off-topic here are we...

The real question is which language is faster. To compare them properly, you need to use the same assumptions:

  • same machine,
  • same design and implementation quality,
  • same specs,
  • etc...

From experience, I know C tends to be preferred over C++ for real-time embedded applications, where CPU and RAM/ROM are limited - precisely for performance and program size reasons.

Post a reply

Please be kind and courteous in your replies. Don't roast others for no reason.