Paste: fibonacci

Author: hotaru
Mode: factor
Date: Tue, 12 Oct 2010 08:46:08
Plain Text |
: twoFibs ( n -- b a ) [ zero? not ]
                     [ 2 /mod [ twoFibs [ dupd 2 * + * ] [ [ sq ] bi@ + ] 2bi ] dip
                       { { 0 [ ] }
                         { 1 [ swap [ + ] keep ] } } case ]
                     [ 0 1 ] smart-if* ;

: fib ( n -- f ) twoFibs drop ;

: fib-matrix ( n -- f ) { { 0 1 } { 1 1 } } swap m^n first second ;

! ( scratchpad ) [ 22390 fib-matrix drop ] time
! Running time: 0.035957084 seconds
! 
! Additional information was collected.
! dispatch-stats.  - Print method dispatch statistics
! gc-events.       - Print all garbage collection events
! gc-stats.        - Print breakdown of different garbage collection events
! gc-summary.      - Print aggregate garbage collection statistics
! ( scratchpad ) gc-summary.
! Collections:          1
! Cards scanned:        142
! Decks scanned:        36
! Code blocks scanned:  3
! Total time:           451 µs
! Card scan time:       356 µs
! Code block scan time: 5 µs
! Data heap sweep time: 0 µs
! Code heap sweep time: 0 µs
! Compaction time:      0 µs
! ( scratchpad ) [ 22390 fib drop ] time
! Running time: 0.007272432 seconds
! 
! Additional information was collected.
! dispatch-stats.  - Print method dispatch statistics
! gc-events.       - Print all garbage collection events
! gc-stats.        - Print breakdown of different garbage collection events
! gc-summary.      - Print aggregate garbage collection statistics
! ( scratchpad ) gc-summary.
! Collections:          0
! Cards scanned:        0
! Decks scanned:        0
! Code blocks scanned:  0
! Total time:           0 µs
! Card scan time:       0 µs
! Code block scan time: 0 µs
! Data heap sweep time: 0 µs
! Code heap sweep time: 0 µs
! Compaction time:      0 µs

New Annotation

Summary:
Author:
Mode:
Body: