-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect-swoole-raw.php
49 lines (35 loc) · 1.33 KB
/
select-swoole-raw.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
42
43
44
45
46
47
48
49
<?php
/**
* This file is part of the Makise-Co Postgres Client
* World line: 0.571024a
*
* (c) Dmitry K. <[email protected]>
*/
declare(strict_types=1);
require_once dirname(__DIR__) . '/vendor/autoload.php';
require_once 'random_data.php';
function seedDataSwoole(\Swoole\Coroutine\PostgreSQL $connection): void
{
$connection->query("DROP TABLE IF EXISTS test");
$connection->query("CREATE TABLE test (domain VARCHAR(63), tld VARCHAR(63), PRIMARY KEY (domain, tld))");
$connection->prepare("insert", "INSERT INTO test VALUES (\$1, \$2)");
foreach (getRandomData() as $row) {
$connection->execute("insert", $row);
}
$connection->query("DEALLOCATE insert");
}
Swoole\Coroutine\run(function () {
$connection = new \Swoole\Coroutine\PostgreSQL();
$connection->connect("host=127.0.0.1 port=5434 user=makise password=el-psy-congroo dbname=makise");
// seedDataSwoole($connection);
$start = microtime(true);
for ($i = 0; $i < 100; $i++) {
$result = $connection->query('SELECT * FROM test');
while ($row = $connection->fetchAssoc($result)) {
}
}
$end = microtime(true);
$total = $end - $start;
printf("Execution time for Swoole client: %f secs\n", $total);
printf("Peak memory usage for Swoole client: %.2f kb\n", memory_get_peak_usage() / 1024);
});