Improved sockets benchmark

db4
Slava Pestov 2008-02-11 16:10:11 -06:00
parent 80c9fe3c83
commit 5c0374ce32
1 changed files with 26 additions and 12 deletions

View File

@ -3,27 +3,41 @@ concurrency tools.time prettyprint ;
IN: benchmark.sockets
: simple-server ( -- )
7777 local-server "simple-server" [
10 [ read1 write1 flush ] times
7777 local-server "benchmark.sockets" [
read1 CHAR: x = [
stop-server
] [
20 [ read1 write1 flush ] times
] if
] with-server ;
: simple-client ( -- )
"localhost" 7777 <inet> <client> [
10 [ CHAR: a dup write1 flush read1 assert= ] times
CHAR: b write1 flush
20 [ CHAR: a dup write1 flush read1 assert= ] times
] with-stream ;
: stop-server ( -- )
"localhost" 7777 <inet> <client> [
CHAR: x write1
] with-stream ;
: socket-benchmark ( n -- )
dup pprint " clients: " write
[ simple-server ] in-thread
yield yield
[ drop simple-client ] parallel-each ;
[
[ simple-server ] in-thread
100 sleep
[ drop simple-client ] parallel-each
stop-server
yield yield
] time ;
: socket-benchmarks
[ 10 socket-benchmark ] time
[ 20 socket-benchmark ] time
[ 40 socket-benchmark ] time
[ 80 socket-benchmark ] time
[ 160 socket-benchmark ] time
[ 320 socket-benchmark ] time ;
10 socket-benchmark
20 socket-benchmark
40 socket-benchmark
80 socket-benchmark
160 socket-benchmark
320 socket-benchmark ;
MAIN: socket-benchmarks