X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=scripts%2Fbench_select_vs_event.php;fp=scripts%2Fbench_select_vs_event.php;h=3bc9aed75c71adbc3ca75dc1759e35d99a8d07b9;hp=0000000000000000000000000000000000000000;hb=bdd6edb59194cda9e5fcb393c48ab4230fceb32a;hpb=c05ef71b26a8d16bf5af2bd8275e08ba5ae02b52 diff --git a/scripts/bench_select_vs_event.php b/scripts/bench_select_vs_event.php new file mode 100644 index 0000000..3bc9aed --- /dev/null +++ b/scripts/bench_select_vs_event.php @@ -0,0 +1,53 @@ + -n -c [-p (enable pipelining)] [-e (use libevent)]\n", $argv[0]); + fprintf(STDERR, "\nDefaults: -u http://localhost/ -n 1000 -c 10\n\n"); + exit(-1); +} + +function push($client, $url, &$n) { + if ($n-- > 0) { + $req = new http\Client\Request("GET", $url); + $client->enqueue($req, function($response) use ($client, $req, $url, &$n) { + global $count; ++$count; + push($client, $url, $n); + return true; // dequeue + }); + } +} + +isset($argv) or $argv = $_SERVER['argv']; +defined('STDERR') or define('STDERR', fopen('php://stderr', 'w')); + +$opts = getopt("u:c:n:e"); +isset($opts["u"]) or $opts["u"] = "http://localhost/"; +isset($opts["c"]) or $opts["c"] = 10; +isset($opts["n"]) or $opts["n"] = 1000; + +$argc > 1 or usage(); + +$time = microtime(true); +$count = 0; +$client = new http\Client; + +$client->enablePipelining($opts["p"]===false); +$client->enableEvents($opts["e"]===false); + +for ($i = 0, $x = $opts["n"]; $i < $opts["c"]; ++$i) { + push($client, $opts["u"], $x); +} + +try { + $client->send(); +} catch (Exception $e) { + echo $e; +} + +printf("\n> %10.6fs (%3.2fM)\n", microtime(true)-$time, memory_get_peak_usage(true)/1024/1024); + +$count == $opts["n"] or printf("\nOnly %d finished\n", $count);