Re: Learning recursion with hailstone seqence



Maarten Wiltink wrote:

1. Can this function be optimised ? (approx 2^67 iterations are
neccessary on current dataset)


It's tail-recursive. You can rewrite it as a loop. Other than that,
there really isn't much room for optimisation - it's a very short
and easy function.

Perhaps using shorter values or using MMX in some way, but I'm not
qualified to say anything about that.

That's all correct, but...

I'd simply wait a few (hundred) years, until a dramatically faster technology becomes available. When a single iteration is performed at 4 GHz, the loop will terminate in about 2000 years.

As a raw guess, I'd predict that the result will be near 42 ;-)

DoDi
.



Relevant Pages

  • Re: Larkin, Power BASIC cannot be THAT good:
    ... Using DDR2 ram execution is roughly 2s and older DDR ram is about 3s in execution. ... A cache aware version of this vector add and accumulate is about 15% faster than the simple loop on a good optimising compiler (actually that is measured on MSC I haven't checked its code generation for optimisation - too tedious). ...
    (sci.electronics.design)
  • Re: wich is faster
    ... On the premature optimisation front - it has to be a judgement call by ... an "& 1" and a simple loop dividing n by odd numbers from 3 to sqrt. ... I do not accept that readability is an excuse ...
    (comp.programming)
  • Re: Letter to US Sen. Byron Dorgan re unpaid overtime
    ... it's a for loop in the C sense. ... > sloppy thinking that results from confusing a programming language ... >> I do not believe that you are capable of writing a conforming C compiler. ... Does Microsoft's C compiler perform this optimisation? ...
    (comp.programming)
  • Re: OT. Good programming techniques (or not)...
    ... It's very easy to turn an Oroutine ... not perform that invariant code optimisation automatically because it ... this is one reason FORTRAN generates faster ... The code has manual loop ...
    (uk.comp.sys.mac)
  • Re: To Richard Heathfield: enoughs enough
    ... And what you called micro optimisation was not micro optimisation. ... > and Optimization are the norm, or that all compilers use yacc, bottom ... hardware that can do 1000 comparisons every clock cycle and figure ... > makes an Ofor loop into an Ofor loop when this for is the ...
    (comp.programming)