2005-05-06 19:49:07 -04:00
|
|
|
USING: compiler kernel math sequences test vectors ;
|
2004-10-27 21:21:31 -04:00
|
|
|
|
|
|
|
|
! http://inferno.bell-labs.com/cm/cs/who/bwk/interps/pap.html
|
|
|
|
|
|
|
|
|
|
: fill-vector ( n -- vector )
|
2006-08-11 16:55:43 -04:00
|
|
|
dup <vector> swap [ dup pick set-nth ] each ;
|
2004-10-27 21:21:31 -04:00
|
|
|
|
|
|
|
|
: copy-elt ( vec-y vec-x n -- )
|
2004-11-15 12:33:21 -05:00
|
|
|
#! Copy nth element from vec-x to vec-y.
|
2006-08-11 16:55:43 -04:00
|
|
|
rot >r tuck >r nth r> r> set-nth ;
|
2004-10-27 21:21:31 -04:00
|
|
|
|
|
|
|
|
: copy-vector ( vec-y vec-x n -- )
|
|
|
|
|
#! Copy first n-1 elements from vec-x to vec-y.
|
2006-08-11 16:55:43 -04:00
|
|
|
[ [ >r 2dup r> copy-elt ] keep ] repeat 2drop ;
|
2004-10-27 21:21:31 -04:00
|
|
|
|
|
|
|
|
: vector-benchmark ( n -- )
|
2006-08-11 16:55:43 -04:00
|
|
|
0 <vector> over fill-vector rot copy-vector ;
|
2004-10-27 21:21:31 -04:00
|
|
|
|
2005-01-29 16:39:30 -05:00
|
|
|
[ ] [ 400000 vector-benchmark ] unit-test
|