Skip to content

Instantly share code, notes, and snippets.

@a-r-m-i-n
Created January 11, 2023 10:29
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 a-r-m-i-n/002cf7963b9f8424faa16ba1c48b4990 to your computer and use it in GitHub Desktop.
Save a-r-m-i-n/002cf7963b9f8424faa16ba1c48b4990 to your computer and use it in GitHub Desktop.
Super simple PHP benchmark script
<?php
// Adjust database credentials in lines 37-40
// And just run on CLI
// On very fast devices the amount of time for each test, should be less than 1 second
$start = microtime(true);
for ($i = 0; $i < 100000000; $i++) {
sqrt($i);
}
$end = microtime(true);
$elapsed = $end - $start;
echo "Calc sqrt: $elapsed seconds\n";
// ---
$start = microtime(true);
for ($i = 0; $i < 500000; $i++) {
$a = file_get_contents(__FILE__);
strlen($a);
}
$end = microtime(true);
$elapsed = $end - $start;
echo "Read File: $elapsed seconds\n";
// ---
$start = microtime(true);
$servername = 'db';
$username = 'root';
$password = 'root';
$database = 'db';
for ($i = 0; $i < 1000; $i++) {
$conn = new \PDO("mysql:host=$servername;dbname=$database", $username, $password);
$conn->query('SHOW TABLES;');
$conn = null;
}
$end = microtime(true);
$elapsed = $end - $start;
echo "Database: $elapsed seconds\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment