]> gitweb.factorcode.org Git - factor.git/blob - apps/benchmarks/strings.factor
aa075a03a2a023e3d339cff8355d7765d6dffcc3
[factor.git] / apps / benchmarks / strings.factor
1 USING: compiler kernel math namespaces sequences strings test ;
2
3 ! http://inferno.bell-labs.com/cm/cs/who/bwk/interps/pap.html
4
5 : string-step ( n str -- )
6     2dup length > [
7         dup [ "123" % % "456" % % "789" % ] "" make
8         dup dup length 2 /i 0 swap rot subseq
9         swap dup length 2 /i 1+ 1 swap rot subseq append
10         string-step
11     ] [
12         2drop
13     ] if ;
14
15 : string-benchmark ( n -- )
16     "abcdef" 10 [ 2dup string-step ] times 2drop ;
17
18 [ ] [ 400000 string-benchmark ] unit-test