Created
January 11, 2023 10:29
-
-
Save a-r-m-i-n/002cf7963b9f8424faa16ba1c48b4990 to your computer and use it in GitHub Desktop.
Super simple PHP benchmark script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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