?

Log in

No account? Create an account
So cmoog made the mistake of mentioning how great C++ is. Being… - CERisE's Testing for L

> Recent Entries
> Archive
> Friends
> Profile

January 19th, 2004


Previous Entry Share Next Entry
03:07 am
So cmoog made the mistake of mentioning how great C++ is.

Being a special interest of mine, I decided to see the current state of things between C and C++ at the moment.

So, two simple programs.

#include <stdio.h>

int main(void)
{
   puts("Hello World!");
   return 0;
}


and

</pre>
#include <iostream.h>

int main(void){
cout<<"Hello World!\n";
return 0;
}
</pre>

Both compiled with gcc -O3
$ ls -l chello cpphello
-rwxr-xr-x    1 root     root         6691 Jan 18 17:28 chello
-rwxr-xr-x    1 root     root         8136 Jan 18 17:27 cpphello

$ time ./chello
Hello World!

real    0m0.004s
user    0m0.001s
sys     0m0.002s

$ time ./cpphello
Hello World!

real    0m0.009s
user    0m0.006s
sys     0m0.002s


Those are representative times (I ran each about 10 times or so and averaged in actuality)

System times are about the same. That makes sense since that's linux printing it to the screen.

Real times are mostly junk. That's the time from start to stop of execution, regardless of what else is going on
in the system.

User times are where it's at. That's the actual time that the code is paged in and executing.

One might notice that C++ takes longer. Significantly longer. This is because of the runtime allocation of the objects in question and cleanup probably. C doesn't bother with that. It interacts directly. This is why C will always beat out C++.

Object Oriented Programming imposes all sorts of strange limitations upon a programmer that aren't true to the machine's capabilities. It's all under the vague and poorly defended pretense that it creates better code. The nastiest bugs that I've ever tracked down have been the result of obfuscation through OOP. In order to do almost any operation, you invoke all sorts of classes one after the next. Many of which are internal compiled libraries which might have interesting issues with cleanup and memory management.

C code when properly placed between files shows the same benefits as distinct objects. C code when properly placed in functions results in clean, readable, compartmentalized code. More of it's under your command and thanks to call stacks, you can easily track down just which function caused the problem.

You also don't have those silly private, public, and protected distinctions.

(1 comment | Leave a comment)

Comments:


From:popt
Date:January 23rd, 2004 02:51 pm (UTC)
(Link)
Damn, that's scary. Someone who thinks like I do about modern programming.

This is one of the reasons I stopped persuing programming about 7 years ago.

> Go to Top
LiveJournal.com