-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path8-benchmark.php
41 lines (32 loc) · 1.17 KB
/
8-benchmark.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
// Usage -----------------------------------------------
// Default (10 x 100 requests): php examples/8-benchmark.php
// Infinite (10 x 100 requests): php examples/8-benchmark.php 0
// Custom (10 x $count requests): php examples/8-benchmark.php $count
use Amp\Artax\Client;
use Amp\Artax\Response;
use Amp\Loop;
use function Amp\coroutine;
require __DIR__ . '/../vendor/autoload.php';
$count = (int) ($argv[1] ?? "1000");
Loop::run(function () use ($count) {
$client = new Amp\Artax\DefaultClient;
$client->setOption(Client::OP_TRANSFER_TIMEOUT, 50000);
$handler = coroutine(function (int $count) use ($client) {
for ($i = 0; $i < $count; $i++) {
/** @var Response $response */
$response = yield $client->request('http://localhost:1337/');
yield $response->getBody();
}
});
do {
$promises = [];
for ($i = 0; $i < 10; $i++) {
$promises[] = $handler($count === 0 ? 100 : $count);
}
yield $promises;
gc_collect_cycles();
gc_mem_caches();
print "Memory: " . (memory_get_usage(true) / 1000) . PHP_EOL;
} while ($count === 0);
});