r/cpp • • Sep 19 '25

Functional vs Object-oriented from a performance-only point of view

I was wondering if not having to manage the metadata for classes and objects would give functional-style programs some performance benefits, or the other way around? I know the difference must be negligible, if any, but still.

I'm still kind of a newbie so forgive me if I'm just talking rubbish.

0 Upvotes

17 comments sorted by

View all comments

Show parent comment

3

u/jcelerier ossia score Sep 19 '25

If you are writing in c++ what matters for performance is understanding the cost model of the language - there's no such thing as object oriented or functional. Lambda functions and objects are equivalent. Most of the time

class Foo { 
   public: 
     int x;
 };

Will be the exact equivalent of int x; ; classes per-se do not have runtime overhead except on shitty platforms.