factor/extra/benchmark/sockets/sockets.factor

44 lines
1023 B
Factor
Raw Normal View History

2008-02-18 08:30:16 -05:00
USING: io.sockets io.server io kernel math threads
2008-02-18 10:08:59 -05:00
debugger tools.time prettyprint concurrency.combinators ;
2008-02-11 16:53:42 -05:00
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 ;
2008-02-14 06:21:02 -05:00
: clients ( n -- )
2008-02-16 19:48:06 -05:00
dup pprint " clients: " write [
2008-02-11 17:10:11 -05:00
[ simple-server ] in-thread
2008-02-16 19:48:06 -05:00
yield yield
2008-02-11 17:10:11 -05:00
[ drop simple-client ] parallel-each
stop-server
yield yield
] time ;
2008-02-11 16:53:42 -05:00
: socket-benchmarks
2008-02-14 06:21:02 -05:00
10 clients
20 clients
40 clients
80 clients
160 clients
320 clients
640 clients ;
2008-02-11 16:53:42 -05:00
MAIN: socket-benchmarks