🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #6545

Re: Weird optimisation results

#6545
From: Bob Gonder
Date: Fri, 29 Apr 2005 18:38
41 lines
2481 bytes
Andrue Cope [TeamB] wrote:

>  long double bigNumber=*( sourceDate++ );
>
>  for( WORD l1=1;
>       l1<8;
>       ++l1,++sourceDate )
>    bigNumber+=( pow( 2, ( long double )( ( l1*8 ) ) )*( *sourceDate )
>);
>  long double secondsSince1601=bigNumber/10000000L;
>....
>
>It occurred to me that replacing this with
>
>void NTDate2APC( BYTE         *sourceDate,
>                 TAPCDateTime *targetDate )
>{
>  QWORD secondsSince1601=
>    ( *reinterpret_cast<QWORD *>( sourceDate ) )/10000000ui64;
>
>would offer a performance improvement.
>
>It doesn't. In fact it gives a performance hit. On my standard NTFS
>test image the old code averages 38 seconds over ten runs. The new code
>averages 34 seconds over ten runs.

The first version uses the FPU which overlaps it's execution with the
cpu, so some of the divide time is "free" while the 
cpu continues on with whatever the ...  entails.
The second method uses 64bit integer division which is quite slow on a
non-64bit cpu.  (As an exercise, try dividing two 16 bit numbers using
only 8 bit registers. Or, with paper and pencil, divide two 4 digit
numbers, looking at only 2 digits at a time. Multiply, not so bad, but
divide is a bear.)
The FPU is also a >64bit unit, so it can handle the division speedily.

>I can appreciate that empirical testing is going to be innaccurate but
>the results seem pretty clear cut. I just don't see how the original
>code can be faster.

The new code will be faster in the future  :-)
Technical Details
Message-ID: <sou471t596qft5josv89hs6femigl430qf@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news2.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4270aa35$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,558eed2a222ed4da
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Weird optimisation results
Date: Fri, 29 Apr 2005 11:38:02 -0700
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <sou471t596qft5josv89hs6femigl430qf@4ax.com>
References: <4270aa35$1@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 69.69.91.96
X-Trace: newsgroups.borland.com 1114799885 69.69.91.96 (29 Apr 2005 11:38:05 -0700)
Lines: 44
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news2.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail