factor/extra/benchmark/ring/ring.factor

28 lines
665 B
Factor
Raw Normal View History

2008-02-18 08:30:16 -05:00
USING: threads concurrency.messaging kernel
tools.time math sequences ;
2007-09-20 18:09:08 -04:00
IN: benchmark.ring
SYMBOL: done
: tunnel ( process -- process )
receive 2dup swap send done eq? [ tunnel ] unless ;
: create-ring ( processes -- target )
2008-02-21 02:25:08 -05:00
self swap [
dup [ tunnel ] curry "Tunnel" spawn nip
] times ;
2007-09-20 18:09:08 -04:00
: send-messages ( messages target -- )
[ dup iota ] dip [ send ] curry each [ receive drop ] times ;
2007-09-20 18:09:08 -04:00
: destroy-ring ( target -- )
done swap send [ done eq? ] receive-if drop ;
: ring-bench ( messages processes -- )
create-ring [ send-messages ] keep destroy-ring ;
2007-09-20 18:09:08 -04:00
: ring-benchmark ( -- )
2007-09-20 18:09:08 -04:00
1000 1000 ring-bench ;
MAIN: ring-benchmark