From 5c0374ce3251f4145bab54bad89a136880a53c95 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Mon, 11 Feb 2008 16:10:11 -0600 Subject: [PATCH] Improved sockets benchmark --- extra/benchmark/sockets/sockets.factor | 38 ++++++++++++++++++-------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/extra/benchmark/sockets/sockets.factor b/extra/benchmark/sockets/sockets.factor index 876ff0b61d..e8efc11c32 100755 --- a/extra/benchmark/sockets/sockets.factor +++ b/extra/benchmark/sockets/sockets.factor @@ -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 [ - 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 [ + 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