<?php
$sql = "SELECT ";
for($i = 0; $i < 1000; $i++){
$sql .= "HOGE";
}
$sql = $sql . "\n" . $sql .";";
$count = 10000;
for($i = 1; $i < 4; $i++){
$start = microtime(true);
for($j = 0; $j < $count; $j++){
$func = "replace$i";
$func($sql);
}
$end = microtime(true);
echo "replace$i:" . ($end - $start) . "\n";
}
function replace1($sql){
//$sql = preg_replace('/(.+);$/s', '\1', trim($sql));
$sql = preg_replace('/;$/s', '', trim($sql));
}
function replace2($sql){
$sql = trim($sql);
$pos = strpos($sql, ";");
if($pos !== false){
$sql = substr($sql, 0, $pos);
}
}
function replace3($sql){
$sql = trim($sql);
$pos = count($sql);
if($sql[$pos] == ";"){
unset($sql[$pos]);
}
}
?>