Skip to content

Instantly share code, notes, and snippets.

@natanfelles
Created December 10, 2018 20:36
Show Gist options
  • Save natanfelles/15b1d253cb285cc8f53a262983ffdf93 to your computer and use it in GitHub Desktop.
Save natanfelles/15b1d253cb285cc8f53a262983ffdf93 to your computer and use it in GitHub Desktop.
<?php
// https://3v4l.org/gDRdq
$foo = 'a/b/c/d/e';
$bar = null;
$m = memory_get_usage();
$t = microtime(true);
for($i = 0; $i < 10000; $i++)
{
$bar = strtr($foo, '/', '-');
}
var_dump(
memory_get_usage() - $m,
microtime(true) - $t
);
echo $bar. "\n";
$bar = null;
$m = memory_get_usage();
$t = microtime(true);
for($i = 0; $i < 10000; $i++)
{
$bar = str_replace('/', '-', $foo);
}
var_dump(
memory_get_usage() - $m,
microtime(true) - $t
);
echo $bar. "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment