Thanks, I tried running a few of them. 
The f0 and f1 series mostly get stack errors way before 475000.
Running timespacex 'f2a 475000' 

34.2436 1.31648e6



timespacex 'f2b 475000' 

34.8053 5.5113e6


f2a and f2b are both non-recursive.


Thanks,
 Jon
> From: rauldmil...@gmail.com
> Date: Wed, 2 Sep 2015 00:04:17 -0400
> To: programm...@jsoftware.com
> Subject: Re: [Jprogramming] Comparing J speed
> 
> There's a variety of fibonacci implementations at
> http://www.jsoftware.com/jwiki/Essays/Fibonacci%20Sequence
> 
> I haven't looked at their timings, but you might find something
> interesting there.
> 
> Good luck,
> 
> -- 
> Raul
> 
> 
> On Tue, Sep 1, 2015 at 8:32 PM, Jon Hough <jgho...@outlook.com> wrote:
> > In this talk https://www.youtube.com/watch?v=apBWkBDVlow
> > the presenter attempts to show Haskell hasn't sacrificed speed for 
> > expressiveness by comparing a Java Fibonacci calculator to his Haskell 
> > one.(skip to the 18:00 mark).Essentially, to calculate the 475000th 
> > Fibonacci number, it took his Java program ~8 seconds, while the very terse 
> > Haskell program took ~6 seconds.
> > So I tried to do the same in J. My first attempt, used a tacit, memoized 
> > verb
> > fib1 =:1:`(($:@:<:) + ($:@:-&2))@.(2&<)M.
> >
> >
> > However, this gives a stack error for large numbers (~100000). So I decided 
> > to make an imperative verb,
> >
> >
> > fib2 =: 3 : 0 x1 =. x:1 x2 =. x:1 c =. 0 while. c < y do. tmp =.  x1 x1 =. 
> > x2 x2 =. tmp + x1 c=.c+1 end. x2
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > )
> >
> >
> > This gets there, I can calculate the 475000th Fibonacci number, but
> >
> >
> > timespacex 'fib2 475000'
> >
> >
> >
> >
> > 36.183 1.31558e6
> >
> >
> > It takes 36 seconds (of course, my hardware is different to that in the 
> > presentation, but still...).
> >
> >
> > Is there a speedier way to do this in J? Preferably a tacit one liner would 
> > also be good.
> >
> >
> > Thanks,
> > Jon
> >
> >
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
                                          
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to