factor/extra/benchmark/sockets/sockets.factor

44 lines
1.0 KiB
Factor
Raw Normal View History

2008-02-11 16:53:42 -05:00
USING: io.sockets io.server io kernel math threads debugger
concurrency tools.time prettyprint ;
IN: benchmark.sockets
: simple-server ( -- )
2008-02-11 17:10:11 -05:00
7777 local-server "benchmark.sockets" [
read1 CHAR: x = [
stop-server
] [
20 [ read1 write1 flush ] times
] if
2008-02-11 16:53:42 -05:00
] with-server ;
: simple-client ( -- )
"localhost" 7777 <inet> <client> [
2008-02-11 17:10:11 -05:00
CHAR: b write1 flush
20 [ CHAR: a dup write1 flush read1 assert= ] times
] with-stream ;
: stop-server ( -- )
"localhost" 7777 <inet> <client> [
CHAR: x write1
2008-02-11 16:53:42 -05:00
] with-stream ;
: socket-benchmark ( n -- )
dup pprint " clients: " write
2008-02-11 17:10:11 -05:00
[
[ simple-server ] in-thread
100 sleep
[ drop simple-client ] parallel-each
stop-server
yield yield
] time ;
2008-02-11 16:53:42 -05:00
: socket-benchmarks
2008-02-11 17:10:11 -05:00
10 socket-benchmark
20 socket-benchmark
40 socket-benchmark
80 socket-benchmark
160 socket-benchmark
320 socket-benchmark ;
2008-02-11 16:53:42 -05:00
MAIN: socket-benchmarks