diff --git a/extra/benchmark/fib6/fib6.factor b/extra/benchmark/fib6/fib6.factor new file mode 100755 index 0000000000..cc42028df6 --- /dev/null +++ b/extra/benchmark/fib6/fib6.factor @@ -0,0 +1,14 @@ +IN: benchmark.fib6 +USING: math kernel alien ; + +: fib + "int" { "int" } "cdecl" [ + dup 1 <= [ drop 1 ] [ + 1- dup fib swap 1- fib + + ] if + ] alien-callback + "int" { "int" } "cdecl" alien-indirect ; + +: fib-main 25 fib drop ; + +MAIN: fib-main diff --git a/extra/benchmark/sockets/sockets.factor b/extra/benchmark/sockets/sockets.factor index 6b1908afb1..c739bb787c 100755 --- a/extra/benchmark/sockets/sockets.factor +++ b/extra/benchmark/sockets/sockets.factor @@ -1,32 +1,54 @@ -USING: io.sockets io.server io kernel math threads -debugger tools.time prettyprint concurrency.combinators ; +USING: io.sockets io kernel math threads +debugger tools.time prettyprint concurrency.count-downs +namespaces arrays continuations ; IN: benchmark.sockets +SYMBOL: counter + +: number-of-requests 1 ; + +: server-addr "127.0.0.1" 7777 ; + +: server-loop ( server -- ) + dup accept [ + [ + read1 CHAR: x = [ + "server" get dispose + ] [ + number-of-requests + [ read1 write1 flush ] times + counter get count-down + ] if + ] with-stream + ] curry "Client handler" spawn drop server-loop ; + : simple-server ( -- ) - 7777 local-server "benchmark.sockets" [ - read1 CHAR: x = [ - stop-server - ] [ - 20 [ read1 write1 flush ] times - ] if - ] with-server ; + [ + server-addr dup "server" set [ + server-loop + ] with-disposal + ] ignore-errors ; : simple-client ( -- ) - "localhost" 7777 [ + server-addr [ CHAR: b write1 flush - 20 [ CHAR: a dup write1 flush read1 assert= ] times + number-of-requests + [ CHAR: a dup write1 flush read1 assert= ] times + counter get count-down ] with-stream ; : stop-server ( -- ) - "localhost" 7777 [ + server-addr [ CHAR: x write1 ] with-stream ; : clients ( n -- ) dup pprint " clients: " write [ - [ simple-server ] in-thread + dup 2 * counter set + [ simple-server ] "Simple server" spawn drop yield yield - [ drop simple-client ] parallel-each + [ [ simple-client ] "Simple client" spawn drop ] times + counter get await stop-server yield yield ] time ;