home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19502 < prev    next >
Encoding:
Text File  |  1993-01-10  |  2.5 KB  |  67 lines

  1. Xref: sparky comp.lang.c:19502 comp.lang.c++:18902
  2. Path: sparky!uunet!spool.mu.edu!agate!forney.berkeley.edu!jbuck
  3. From: jbuck@forney.berkeley.edu (Joe Buck)
  4. Newsgroups: comp.lang.c,comp.lang.c++
  5. Subject: Re: C/C++ Speed
  6. Date: 10 Jan 1993 21:31:31 GMT
  7. Organization: U. C. Berkeley
  8. Lines: 53
  9. Distribution: usa
  10. Message-ID: <1iq4jj$5fr@agate.berkeley.edu>
  11. References: <1ipsk5INNf5m@aludra.usc.edu>
  12. NNTP-Posting-Host: forney.berkeley.edu
  13.  
  14. In article <1ipsk5INNf5m@aludra.usc.edu> dliao@aludra.usc.edu (David Liao) writes:
  15. >    Two programmers are writing the same program but with different
  16. >languages which are C and C++.  These two programmers are experts in 
  17. >their own programming language.  Hmm... which program will run faster
  18. >than the other?
  19.  
  20. Unknown.  It depends on design decisions, the quality of the compilers
  21. each programmer uses, how much time is spent tuning the application for
  22. speed, etc.
  23.  
  24. >    I've heard that the execution speed of C++ tends to be slower
  25. >than C.
  26.  
  27. Sorry, this is not true.  Almost every C++ compiler either generates C
  28. code or shares a back end with some C compiler.  This means that
  29. equivalent constructs take the same amount of time.  While it is true
  30. that a virtual function call takes slightly more time than a direct
  31. call, it also does more than the direct function call does.  In many
  32. cases, the C++ solution can be faster than the one that the C programmer
  33. would most naturally come up with (because lots of if() and switch()
  34. statements are eliminated).
  35.  
  36. >  I know that C++ can make the life of programmer easier, but
  37. >I just want to know if the C program will run faster than the C++ program.
  38.  
  39. There's no reason to think so.
  40.  
  41. >    I also heard the size of C++ program is generally bigger than C.
  42. >I am a C programmer trying to learn C++.  So, don't blame me if I have 
  43. >created any misconception about C++.
  44.  
  45. C++ programmers typically tackle larger problems than C programmers;
  46. there is no fundamental reason for C++ programs to be larger, unless
  47. you consider the size of tiny programs.  That is, if you compare the
  48. size of
  49.  
  50. #include <stdio.h>
  51. int main() { printf("Hello, world\n");}
  52.  
  53. to
  54.  
  55. #include <iostream.h>
  56. int main() { cout << "Hello, world\n";}
  57.  
  58. you are really comparing the size of the printf routine and the size
  59. of the iostream class, and the latter will be a good bit larger.  But
  60. this difference is inconsequential in any program of substantial size,
  61. and once things start getting big the class libraries start saving on
  62. code size if used properly.
  63.  
  64.  
  65. --
  66. Joe Buck    jbuck@ohm.berkeley.edu
  67.