Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: Borland Turbo C++ performance issue and tutorial errors Message-ID: <380@taumet.com> Date: 4 Aug 90 20:22:12 GMT References: <7921@tekgvs.LABS.TEK.COM> Organization: Taumetric Corporation, San Diego Lines: 52 toma@tekgvs.LABS.TEK.COM (Tom Almy) writes: |It has already been pointed out that Turbo C++ is slower compiling a C program |that Turbo C V2.0. But the problem gets worse with C++ programs (the larger |header files are mostly to blame). Executables are bigger as well. For |instance, compare hello.c with hello.cpp: | C C++ |Compile time: 2 sec 3.8 sec |Executable size: 6074 17852 |(The c program does printf("Hello world"), while the c++ program does | cout << "Hello world". You have to be very careful in such comparisons. Any C++ program using streams includes the entire stream i/o package, which is very large. It has much more functionality than does printf(), so it is bigger. You could also compare a C program which used write(1, "Hello, world", 12); in place of printf() and get a smaller program -- because write has much less functionality than printf(). Besides, you can use printf() instead of streams in C++ if you wish. |The calc program example from the Stroustrup book (with addition of trig |functions) compiles to a 35440 byte file, while the same program rewritten |in JPI Modula-2 (just to test it out) is 11510. (The source file in C++ is |60% the size, though!). There can be no validity to a claim that two programs written in two different programming languages are the "same". It is a well-known theorem in the theory of computation that one cannot *in general* determine whether two programs have the same behavior. Apart from that, you are looking at a) Different functionality of C++ stream i/o vs Modula-2 i/o. b) Differences in implementation of floating-point operations. (Are you linking in comparable FP libraries? Does one of the programs include both 80x87 and software FP?) c) Differences in quality of code generation. IMHO, comparing executable file size for toy programs is an entirely irrelevant exercise. You are really comparing runtime library size, which completely swamps anything in the toy program. In the above case, we can see that *without floating-point*, the basic Turbo C++ runtime library for any program using stream i/o is 17K, assuming debugging was in fact disabled. If you really just want to say hello, use write() instead of using stream i/o. If you are writing a clone of 1-2-3 or WordPerfect, the 40% reduction in source file size seems far more relevant than a few percent difference in executable file size. -- Steve Clamage, TauMetric Corp, steve@taumet.com