home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c:19502 comp.lang.c++:18902
- Path: sparky!uunet!spool.mu.edu!agate!forney.berkeley.edu!jbuck
- From: jbuck@forney.berkeley.edu (Joe Buck)
- Newsgroups: comp.lang.c,comp.lang.c++
- Subject: Re: C/C++ Speed
- Date: 10 Jan 1993 21:31:31 GMT
- Organization: U. C. Berkeley
- Lines: 53
- Distribution: usa
- Message-ID: <1iq4jj$5fr@agate.berkeley.edu>
- References: <1ipsk5INNf5m@aludra.usc.edu>
- NNTP-Posting-Host: forney.berkeley.edu
-
- In article <1ipsk5INNf5m@aludra.usc.edu> dliao@aludra.usc.edu (David Liao) writes:
- > Two programmers are writing the same program but with different
- >languages which are C and C++. These two programmers are experts in
- >their own programming language. Hmm... which program will run faster
- >than the other?
-
- Unknown. It depends on design decisions, the quality of the compilers
- each programmer uses, how much time is spent tuning the application for
- speed, etc.
-
- > I've heard that the execution speed of C++ tends to be slower
- >than C.
-
- Sorry, this is not true. Almost every C++ compiler either generates C
- code or shares a back end with some C compiler. This means that
- equivalent constructs take the same amount of time. While it is true
- that a virtual function call takes slightly more time than a direct
- call, it also does more than the direct function call does. In many
- cases, the C++ solution can be faster than the one that the C programmer
- would most naturally come up with (because lots of if() and switch()
- statements are eliminated).
-
- > I know that C++ can make the life of programmer easier, but
- >I just want to know if the C program will run faster than the C++ program.
-
- There's no reason to think so.
-
- > I also heard the size of C++ program is generally bigger than C.
- >I am a C programmer trying to learn C++. So, don't blame me if I have
- >created any misconception about C++.
-
- C++ programmers typically tackle larger problems than C programmers;
- there is no fundamental reason for C++ programs to be larger, unless
- you consider the size of tiny programs. That is, if you compare the
- size of
-
- #include <stdio.h>
- int main() { printf("Hello, world\n");}
-
- to
-
- #include <iostream.h>
- int main() { cout << "Hello, world\n";}
-
- you are really comparing the size of the printf routine and the size
- of the iostream class, and the latter will be a good bit larger. But
- this difference is inconsequential in any program of substantial size,
- and once things start getting big the class libraries start saving on
- code size if used properly.
-
-
- --
- Joe Buck jbuck@ohm.berkeley.edu
-