- substr: documentation ( source)
- rtrim: documentation ( source)
- microtime: documentation ( source)
<?php
$path = '/some/path/';
$start = microtime(true);
for ($i = 0; $i < 100000; $i++) {
if (substr( $path, -1 ) == '/') $path = substr( $path, 0, -1 );
}
$end = microtime(true);
echo "<br>\n" . $end - $start;
$path = '/some/path';
$start = microtime(true);
for ($i = 0; $i < 100000; $i++) {
if (substr( $path, -1 ) == '/') $path = substr( $path, 0, -1 );
}
$end = microtime(true);
echo "<br>\n" . $end - $start;
$path = '/some/path/';
$start = microtime(true);
for ($i = 0; $i < 100000; $i++) {
$path = rtrim($path, '/');
}
$end = microtime(true);
echo "<br>\n" . $end - $start;
$path = '/some/path';
$start = microtime(true);
for ($i = 0; $i < 100000; $i++) {
$path = rtrim($path, '/');
}
$end = microtime(true);
echo "<br>\n" . $end - $start;