Re: Automatically transform or expand do loop in a subroutine



On Wed, 30 Jan 2008 23:25:01 -0800, Richard Maine <nospam@xxxxxxxxxxxxx>
wrote in <1ibjyb7.1hw8i1tx9pokqN%nospam@xxxxxxxxxxxxx>:
highegg <highegg@xxxxxxxxx> wrote:

On Jan 31, 7:06 am, nos...@xxxxxxxxxxxxx (Richard Maine) wrote:
yaqi <yaqiw...@xxxxxxxxx> wrote:
I want to save computing time as much as I can.

...

do i=1,d
c = c + i
end do

The "obvious" way to save a lot of computing time here is to replace the
loop with

c = c + d*i

certainly not. c = c + d*(d+1)/2, more likely :)

Um. Er. Right.

I remember getting a fairly righteous reply from Jerry Pournelle
back in the late 80s when I pointed out to him that his "Benchmark of
Sorts" (or some such phrase) in BYTE at the time turned out to be exactly
that, and using the transform brought the "benchmark" down fron something
like a few minutes to 1/40 sec on a PC/AT[1]. The essence of the reply
was, "That's not the point"!

[1] It may have been even more drastic. Short of hunting through all my
archives, my memory's the only resource I've got.

--
Ivan Reid, School of Engineering & Design, _____________ CMS Collaboration,
Brunel University. Ivan.Reid@[brunel.ac.uk|cern.ch] Room 40-1-B12, CERN
KotPT -- "for stupidity above and beyond the call of duty".
.



Relevant Pages

  • Re: Why is C# 450% slower than C++ on nested loops ??
    ... The posted benchmark was crucial to ... > compilers generate for the loop and get over with it. ... > additions in the outer loops, which the C# compiler doesn't. ... gotten around to implementing every possible optimization in every language, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Bit-order reversal (little-endian <--> big-endian)
    ... The only thing I did with your do loop is ... copy and paste it into a benchmark app. ... Certainly you can use a standard if then statement instead of the IIF. ... design is faster as it avoids extra iterations. ...
    (microsoft.public.vb.general.discussion)
  • Re: Test cpu speed
    ... Certainly if you run this benchmark on two CPUs with exactly the same ... CPU will run these faster. ... possibly exceeding the instruction cache. ... As the loop contents ...
    (comp.soft-sys.matlab)
  • Re: circular shifting a vector/matrix - Problem
    ... Unfortunately circshift is a handy function, ... knocked up this fast and dirty benchmark to give you an idea of how to do ... in a very straigthforward way and still in a loop if that's ... I am using "corr2" as a way to compute the similarity between these ...
    (comp.soft-sys.matlab)
  • Re: string comparison
    ... > hoops to "make it work". ... No need to jump through hoops: ... My gut feeling is that the loop with eq will ... I'll try benchmark later. ...
    (comp.lang.perl.misc)