home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19506 < prev    next >
Encoding:
Internet Message Format  |  1993-01-10  |  2.8 KB

  1. Xref: sparky comp.lang.c:19506 comp.lang.c++:18903
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!asuvax!ncar!noao!amethyst!organpipe.uug.arizona.edu!news
  3. From: dave@cs.arizona.edu (Dave Schaumann)
  4. Newsgroups: comp.lang.c,comp.lang.c++
  5. Subject: Re: C/C++ Speed
  6. Message-ID: <1993Jan10.215947.13520@organpipe.uug.arizona.edu>
  7. Date: 10 Jan 93 21:59:47 GMT
  8. References: <1ipsk5INNf5m@aludra.usc.edu>
  9. Sender: news@organpipe.uug.arizona.edu
  10. Reply-To: dave@cs.arizona.edu (Dave Schaumann)
  11. Followup-To: comp.lang.c
  12. Distribution: usa
  13. Organization: University of Arizona
  14. Lines: 52
  15. In-Reply-To: dliao@aludra.usc.edu (David Liao)
  16.  
  17. In article <1ipsk5INNf5m@aludra.usc.edu>, dliao@aludra (David Liao) writes:
  18. >
  19. >    Two programmers are writing the same program but with different
  20. >languages which are C and C++.  These two programmers are experts in 
  21. >their own programming language.  Hmm... which program will run faster
  22. >than the other?
  23.  
  24. Probably the C program, but...
  25.  
  26. Choosing a target language *always* involves trade-offs.  C has several
  27. advantages in its favor that tend to make C programs run faster:
  28.  
  29.   1. C is a smaller language than C++.  This means a company with $X to
  30.      spend on developing a C compiler will have more money left over when
  31.      it comes time to think about optimizing.
  32.  
  33.   2. C is more widely used, so more money is spent developing C compilers,
  34.      and so the level of technology you're likely to encounter for C
  35.      compilers is likely to be superior.
  36.  
  37.   3. C++ does have some features which might cause code to run slow.
  38.      Since it's a more powerful language than C, it also has more features
  39.      that can be abused.
  40.  
  41. >I just want to know if the C program will run faster than the C++ program.
  42.  
  43. Last semester, I had a graphics class, and the final project was to write
  44. an interactive program that drew Bezier curves, with up to 50 segments.
  45. We were allowed to choose the language, so there were people using the
  46. (Sun 4) vendor cc, some using gcc.  I used g++ (I don't know if anyone
  47. else did, though).  I was able to obtain very satisfactory performance
  48. with my program.  I would even say that I was able to more easily implement
  49. some optimizations (such as utilizing pre-computed screen coordinates)
  50. because of the class structure available.
  51.  
  52. I realize this isn't "iron-clad proof", but my experience indicates that
  53. unless you're really pushing the envelope, you can get competative
  54. performance out of a C++ program.
  55.  
  56.  
  57. >    I also heard the size of C++ program is generally bigger than C.
  58.  
  59. I just brought this up myself a few weeks ago.  The answer is that it is
  60. possible to compile C++ programs to be very comparable to the size of an
  61. equivalent C program.
  62.  
  63. On the other hand, there are some compilers out there that can generate
  64. very large executables.
  65.  
  66. -- 
  67. What I've learned from reading net news #2:
  68.   Surely the most ignored phrase to be posted to the net is "'nuff said".
  69.