delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/12/25/08:21:32

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
Message-ID: <3C248C53.AF6F7DED@yahoo.com>
From: CBFalconer <cbfalconer AT yahoo DOT com>
Organization: Ched Research
X-Mailer: Mozilla 4.75 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.lang.c,comp.os.msdos.djgpp
Subject: Re: C 67% faster than C++?!
References: <1009003660 DOT 300355 AT news>
Lines: 64
Date: Sat, 22 Dec 2001 14:10:48 GMT
NNTP-Posting-Host: 12.90.174.145
X-Complaints-To: abuse AT worldnet DOT att DOT net
X-Trace: bgtnsc04-news.ops.worldnet.att.net 1009030248 12.90.174.145 (Sat, 22 Dec 2001 14:10:48 GMT)
NNTP-Posting-Date: Sat, 22 Dec 2001 14:10:48 GMT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

C_CPP_guy wrote:
> 
> cleaning up/rewriting some code from C to C++ I noticed that there
> was a speed degradation that, to me, was not caused by my coding.
> The program is I/O intensive. It counts all charaters in a file
> and saves their offsets and and then checks that the saved values
> are right.
> 
> As data feeds I use small and large text and binary files and I
> used VC++6 as env. , but also tested the code using deloire's
> djgpp to make sure it was ANSI C/C++.
> 
> In both cases code was compiled for speed; /O2 compiler option.
> 
> /nologo /MLd /W3 /Gm /GX /O2 /D "WIN32" /D "_DEBUG" /D "_CONSOLE"
> /D "_MBCS" /Fp"Debug/std_char_ptr.pch" /YX /Fo"Debug/" /Fd"Debug/"
> /FD /c
> 
> Here are my questions.
> 
> Questions:
> ._ I have always heard local arrays are faster then heap based
> ones. I tested it and found no difference whatsoever. So, what is
> it I don't quite understand here?
> 
> ._ The same algorithm coded in plain ANSI C is 67% faster. Scott
> Meyers and many other C++ gurus state that there is no or very
> little, 5%, speed difference between C and C++ programs. What is
> it I am doing wrong here?
> 
> ._ Is this the most optimal compiler setting for speed using
> Win32/VC++?

... snip code ...

I would be much more inclined to try to compile those if the code
came over unharmed.  This means keeping line length under about
72, and NOT using // comments.  Just the use of those comments
makes the C code non-compliant under C90.  Your djgpp/gcc compile
should have showed that up if you used suitable flags (-W -ansi
-Wall -pedantic -O2)

The same line length limit should also apply to your article. 
BTW, that's delorie, not deloire.

The speed difference between using malloc and local storage is not
in the use, but in the getting.  Local allocation is normally
something like an add to a register on function entry (sp on the
x86), while malloc, and the accompanying free, are system calls.

The way to put your finger on the speed differences is to
profile.  You will probably find the hot spots are different.

PS: I later found your article multi-posted on
comp.os.msdos.djgpp.  Don't do that, cross post instead.  That way
I would not have been bothered by having it appear twice, and the
thread is joined between the two groups.

-- 
Chuck F (cbfalconer AT yahoo DOT com) (cbfalconer AT XXXXworldnet DOT att DOT net)
   Available for consulting/temporary embedded and systems.
   (Remove "XXXX" from reply address. yahoo works unmodified)
   mailto:uce AT ftc DOT gov  (for spambots to harvest)

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019