Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2000:
[Freeciv-Dev] Re: #define $#@$%! template
Home

[Freeciv-Dev] Re: #define $#@$%! template

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: #define $#@$%! template
From: Vasco Alexandre Da Silva Costa <vasc@xxxxxxxxxxxxxxx>
Date: Thu, 27 Apr 2000 23:03:20 +0100 (WET DST)

On Thu, 27 Apr 2000, Tomasz Wegrzanowski wrote:

> On Wed, Apr 26, 2000 at 09:05:10PM -0500, Michael H. Price II wrote:
> > On Thu, Apr 27, 2000 at 01:00:29AM +0200, Tomasz Wegrzanowski wrote:

Sorry to take part in this C vs C++ holy war, but i just can't pass these
things up when they happen ;)

> > > - c++ compiler makes worse code
> > 
> > People write worse code because they don't know the language as well
> > as they think they do. Write proper C++ code and you will get very
> > good code from any modern compiler. I challenge you to provide an
> > example supporting your claim.
> 
> I accept your challenge
> 
> testing script `ctest' :
> --- start ---
> #!/bin/sh
> time for n in 1 2 3 4 5 6 7 8 9 10 ; do  gcc hello.c -o c ; done
> time for n in 1 2 3 4 5 6 7 8 9 10 ; do  g++ hello.C -o cplus ; done
> ls -l c cplus
> time for n in 1 2 3 4 5 6 7 8 9 10 ; do ./c ; done
> time for n in 1 2 3 4 5 6 7 8 9 10 ; do ./cplus ; done
> --- end ---
> 
> (hello.c and hello.C are both links to hello, this is the most fair way I 
> found)
> 
> hello file :
> --- start ---
> int main () {
> return 0;
> }
> --- end ---
> 
> (there is NO easier file)
> 
> $ ./ctest >log 2>&1
> $ cat log
> --- start ---
> real  0m3.514s
> user  0m2.280s
> sys   0m0.830s
> 
> real  0m5.900s
> user  0m3.130s
> sys   0m0.990s
> -rwxrwxr-x    1 bashiz   bashiz       4583 Apr 27 17:25 c
> -rwxrwxr-x    1 bashiz   bashiz       4977 Apr 27 17:25 cplus
> 
> real  0m0.079s
> user  0m0.020s
> sys   0m0.060s
> 
> real  0m0.275s
> user  0m0.150s
> sys   0m0.030s
> --- end ---
> 
> As you see, c++ compiler runs slower, makes bigger code, makes slower code
> for simplest hello code. I have also tried more complex code :

That point is moot unless you "strip" the executable and/or turn on
optimization.

> --- start ---
> #include "stdio.h"
> 
> int main () {
> printf ("Hello, world\n");
> return 0;
> }
> --- end ---
> 
> $ ./ctest >log 2>&1
> $ cat log
> --- start ---
> real  0m7.110s
> user  0m3.160s
> sys   0m1.070s
> 
> real  0m9.636s
> user  0m4.470s
> sys   0m1.190s
> -rwxrwxr-x    1 bashiz   bashiz       4717 Apr 27 17:35 c
> -rwxrwxr-x    1 bashiz   bashiz       5115 Apr 27 17:35 cplus
(snip)
> 
> real  0m0.089s
> user  0m0.030s
> sys   0m0.050s
(snip)
> real  0m0.953s
> user  0m0.150s
> sys   0m0.080s
> --- end ---
> 
> Again, slower compiler, bigger code, slower code.
> I have tried to check assembler output,
> c and objc make the same code
> c++ adds twice much labels and some strange db's list on the end

> What do you think ???

Like i thought... If labels are the problem just strip'ing the executable
will rip them away.  Unacessible code  (if present) will be removed by the
'-O' option in gcc for both C & C++ (since that turns on some of the
simpler global code optimizations).  Jumps to the next instruction should
be removed also, etc.

I'm no fan of C++, i find myself much more comfortable of using C most
times, but C++ has it's uses, and C++ compilers aren't as unefficient as
some people think.

PS: if you notice carefully both C & C++ executables include the .comment
section on them which adds some infuriating extra letters on them with the
compiler name.

If you really care for such things as executable size of such minute
programs try this page for a good laugh :)

http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html

This includes a version of a program similar to the first one you posted
with 45 bytes (gasp!) of executable size...

---
Vasco Alexandre da Silva Costa @ Instituto Superior Tecnico, Lisboa




[Prev in Thread] Current Thread [Next in Thread]