2005-04-29 02:37:12 -04:00
|
|
|
USING: compiler kernel math namespaces sequences strings test ;
|
2004-10-27 21:21:31 -04:00
|
|
|
|
|
|
|
! http://inferno.bell-labs.com/cm/cs/who/bwk/interps/pap.html
|
|
|
|
|
|
|
|
: string-step ( n str -- )
|
2005-04-29 02:37:12 -04:00
|
|
|
2dup length > [
|
2005-08-25 15:27:38 -04:00
|
|
|
dup [ "123" % % "456" % % "789" % ] "" make
|
2005-05-18 16:26:22 -04:00
|
|
|
dup dup length 2 /i 0 swap rot subseq
|
2005-09-16 22:47:28 -04:00
|
|
|
swap dup length 2 /i 1+ 1 swap rot subseq append
|
2004-10-27 21:21:31 -04:00
|
|
|
string-step
|
|
|
|
] [
|
|
|
|
2drop
|
2005-09-24 15:21:17 -04:00
|
|
|
] if ; compiled
|
2004-10-27 21:21:31 -04:00
|
|
|
|
|
|
|
: string-benchmark ( n -- )
|
2004-12-17 19:27:42 -05:00
|
|
|
"abcdef" 10 [ 2dup string-step ] times 2drop ; compiled
|
2004-10-27 21:21:31 -04:00
|
|
|
|
2005-01-30 15:57:25 -05:00
|
|
|
[ ] [ 400000 string-benchmark ] unit-test
|