On Sep 11, 2009, at 8:53 AM, Derick Eddington wrote:

Darn, my stack-lang implementation sucks:

:-)

...
$ ikarus -O2 --r6rs-script fib.sps
running stats for (S 34 fib):
   335 collections
   6732 ms elapsed cpu time, including 168 ms collecting
   7213 ms elapsed real time, including 187 ms collecting
   1402578680 bytes allocated

Notice the 1.4gbs you're allocating.  That's not cheap.

running stats for (scheme-fib 34):
   no collections
   317 ms elapsed cpu time, including 0 ms collecting
   331 ms elapsed real time, including 0 ms collecting
   0 bytes allocated

Notice the 0b allocated.

$ factor -run=listener
0.587815 seconds
Total GC time:    0       0     0

Notice the 0s here too.

As you can see, the same algorithm took mine 7.2 seconds and took Factor
only 0.6 second.

There's hope then!

I'm not sure why mine is so slow. I suspect it's because my data stack
is an SRFI-39 parameter and it is used heavily.

That's a contributor.  You might get it down to 2 secs if you refrain
from side effects.

 I'm going to change my
implementation to pass and return the data stack through "word"
procedure calls, to see if that helps.

Also think about how to optimize the common cases: procedures that take
two arguments and return one value.  You probably also need to inline
common words like push, pop, dup, etc.  I think you can get very close
to factor's speed since scheme-fac can do it in 0.3 secs, so, you can
burn twice the work and still be comparable to factor.

Aziz,,,

Reply via email to