Tuesday, December 14, 2004

Re: which is faster : C or C++?

I guess I didn't pose my question very clearly... will try to do it in this post. First of all, I must clarify that I am as big a fan of C++ as anybody can be and I'd choose C++ over C almost ALL the time unless it's absolutely necessary to use C. It's that particular 'absolutely necessary' case I'm examining here. All the things you guys have written make sense and I agree completely.

While that little function overhead is insignificant in most cases and is nothing compared to the IMMENSE additional flexibility and functionality that you gain, it would be worthwhile contemplating under what circumstances this overhead could become significant. Codes that go into CFD applications can take ridiculously long time to execute. Let's say a C++ code that does the same thing as a 5 sec C code takes 7.5 sec to execute. Doesn't seem much... you don't give a damn. Stick to C++. But when you're talking about 50 and 75 DAYS, the difference is HUGE. And I'm not kidding here. There are codes which take that long to execute.

So, if I want to write such code (if?... hell I DO have to write such code), which is a better option - C or C++? In this case, is it right to say that you could use all the good organisation and 'cleanliness' of using classes and get the same performance if you let go of virtual functions?

Once again, except for this case of infinitely large execution times, C++ is a better option than C... no doubt about it. But what about this case?


No comments: