Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!dptg!pegasus!psrc From: psrc@pegasus.ATT.COM (Paul S. R. Chisholm) Newsgroups: comp.lang.c++ Subject: Re: Efficiency of C++ relative to C?? Message-ID: <4102@pegasus.ATT.COM> Date: 20 Sep 89 13:38:46 GMT References: <16493@watdragon.waterloo.edu> <9924@alice.UUCP> Organization: AT&T Bell Laboratories Lines: 48 > In article <16493@watdragon.waterloo.edu>, dvadura@watdragon.waterloo.edu (Dennis Vadura) asks how efficient C++ is. C++ has virtual functions, which are less efficient that C functions (but more efficient than a switch and a function call), and inline functions, which are more (time) efficient than C functions. A "normal" C++ function call, or a non-virtual member function call, is exactly as efficient as a C function call. I think some studies were done (don't ask me for references) where someone re-wrote a C program in C++; the result was a faster program. This isn't a particularly good experiment (you need to have someone re-write the same application in C, to see what the effects of re-writing are, as opposed to the effects of C++). Certainly C++, like C, was written so a good programmer can write small, fast programs. In article <9924@alice.UUCP>, shopiro@alice.UUCP (Jonathan Shopiro) writes: > So, if you're using C now and you're unhappy with it because even > though you are a very good C programmer, your programs don't run fast > enough, C++ is unlikely to help you much (or at all). Try assembly > language or a better optimizer. Rather, try applying "the two laws of program efficiency": (1) Make it right before you make it fast. (If you don't care if it's right, replace it with "Hello, world"; that runs *much* faster!-) (2) Measure it, and only work on the parts of the program that take up the most time. (That is, profile your program, find the ten percent of the code the program spends most of its time in, and work on that part.) If there's a third law, it's to pick a fast algorithm, rather than twiddling a slow one. I recommend Jon Louis Bentley's WRITING EFFICIENT PROGRAMS (1982, Prentice-Hall, ISBN 0-13-970244-X) for lots of insight into this topic. (Or buy faster hardware, if you can afford it.) > Jonathan Shopiro, research!shopiro Paul S. R. Chisholm, AT&T Bell Laboratories att!pegasus!psrc, psrc@pegasus.att.com, AT&T Mail !psrchisholm I'm not speaking for the company, I'm just speaking my mind.