Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.lang.c Subject: Re: a = b or memset/cpy? Date: Thu, 09 Feb 2012 09:18:58 +1300 Lines: 35 Message-ID: <9pg3liFom1U3@mid.individual.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net iFOvZUZlwpT5Jpy3sQiY2ge8a7GEqUHxAmMCG88AD9j3Zqyjoi Cancel-Lock: sha1:CoMYZY0Rm1TAJ7sxwtHGaKZPbJM= User-Agent: Mozilla/5.0 (X11; SunOS i86pc; rv:6.0.2) Gecko/20111003 Thunderbird/6.0.2 In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:16937 On 02/ 9/12 09:05 AM, Joe keane wrote: > In article, > nroberts wrote: >> memset and memcpy are turning up in profiles a lot. > > Indeed. > >> Sometimes it is clear that using = to initialize a local would be >> better than memset. > > It's a shame if you call a function with a size parameter, when in fact > the size is a compile-time constant. You also probably know a bit about > alignment, whereas those guys have to assume the worst. A decent compiler will inline the call to memset() in this case, so there is no call overhead. Whether the inline memset() is faster or slower than an assignment to a const initialiser is something the OP would have to measure. >> I might not gain anything, but at least there's a chance. > > Please to use real data! 'gprof' is very good at this. It works [so > far as i have seen] on stdlib calls as well as your functions. Assuming the OP uses GNU tools... > It can tell you where you're getting killed by function call overhead, > and where the copy is taking a long time, such that you may go to more > length to avoid it. It can also (by switching back to a function) tell > you where your 'optimization' does nothing except increase code size. Assuming there is a function call... -- Ian Collins