Skip to content

Instantly share code, notes, and snippets.

@shin1x1
Created December 10, 2021 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shin1x1/0f6a094c88318161f024f866b136d57b to your computer and use it in GitHub Desktop.
Save shin1x1/0f6a094c88318161f024f866b136d57b to your computer and use it in GitHub Desktop.
<?php
const LOOP = 50;
$mesuare = function (string $title, callable $func): void {
printf("<h2>%s</h2>", htmlspecialchars($title));
for ($i = 1; $i <= LOOP; $i++) {
$start = microtime(true);
$time = $func() - $start;
$mark = $time > 5.0 ? ' <==' : '';
printf('case%02d: %f%s<br>', $i, $time, $mark);
flush();
usleep(1000);
}
};
$mesuare(
'pg_connect',
function (): float {
$conn = pg_connect('host=db dbname=app user=app password=pass');
$time = microtime(true);
pg_close($conn);
return $time;
}
);
$mesuare(
'PDO',
function (): float {
$pdo = new PDO('pgsql:host=db;dbname=app', 'app', 'pass');
$time = microtime(true);
$pdo = null;
return $time;
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment