rendered paste body<?php
function getmicrotime($t){
list($usec, $sec) = explode(" ",$t);
return ((float)$usec + (float)$sec);
}
$benchmark_start = microtime(true);
$trans = array("h" => "-", "hello" => "hi", "hi" => "hello");
for($i = 0; $i < 50000; $i++) {
$out = strtr("hi all, I said hello", $trans);
}
$benchmark_stop = microtime(true);
$benchmark_total = getmicrotime($benchmark_stop) - getmicrotime($benchmark_start);
echo "Time: ". $benchmark_total." seconds\n";
####
$benchmark_start = microtime(true);
$trans = array();
$sub = '';
for($i = 0; $i < 2000; $i++) {
$trans['hi'.$i] = 'hello'.$i;
$sub .= "hi{$i} all, I said hello\n";
}
for($i = 0; $i < 1000; $i++) {
$out = strtr($sub, $trans);
}
$benchmark_stop = microtime(true);
$benchmark_total = getmicrotime($benchmark_stop) - getmicrotime($benchmark_start);
echo "Time: ". $benchmark_total." seconds\n";