Skip to content

Instantly share code, notes, and snippets.

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 goosehub/bb64499ede14004d9e3dbb256cb03227 to your computer and use it in GitHub Desktop.
Save goosehub/bb64499ede14004d9e3dbb256cb03227 to your computer and use it in GitHub Desktop.
strtolower() vs strtoupper performance test
<?php
$string = 'hello world';
$start_time = microtime();
for ($i = 0; $i < $max = 10000000; $i++) {
strtolower($string);
}
$timed = microtime() - $start_time;
echo 'strtolower ' . $string . ' - ' . $timed . '<br>';
$string = 'hello world';
$start_time = microtime();
for ($i = 0; $i < $max = 10000000; $i++) {
strtoupper($string);
}
$timed = microtime() - $start_time;
echo 'strtoupper ' . $string . ' - ' . $timed . '<br>';
$string = 'HELLO WORLD';
$start_time = microtime();
for ($i = 0; $i < $max = 10000000; $i++) {
strtolower($string);
}
$timed = microtime() - $start_time;
echo 'strtolower ' . $string . ' - ' . $timed . '<br>';
$string = 'HELLO WORLD';
$start_time = microtime();
for ($i = 0; $i < $max = 10000000; $i++) {
strtoupper($string);
}
$timed = microtime() - $start_time;
echo 'strtoupper ' . $string . ' - ' . $timed . '<br>';
$string = 'Hello World';
$start_time = microtime();
for ($i = 0; $i < $max = 10000000; $i++) {
strtolower($string);
}
$timed = microtime() - $start_time;
echo 'strtolower ' . $string . ' - ' . $timed . '<br>';
$string = 'Hello World';
$start_time = microtime();
for ($i = 0; $i < $max = 10000000; $i++) {
strtoupper($string);
}
$timed = microtime() - $start_time;
echo 'strtoupper ' . $string . ' - ' . $timed . '<br>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment