<?php
function timer($reset = false) {
global $TIMER;
if ($reset) $TIMER = 0;
list($sec, $msec) = explode(' ', microtime());
$TIMER = $sec + $msec - $TIMER;
}
$t = 0;
$N = 5;
for ($i = 0; $i < $N; $i++){
timer(true);
/*
// 2,2 sec - 30 MB
$fd=fopen("file1.txt","r");
$str=fread($fd,filesize("file1.txt"));
fclose($fd);
$str=preg_replace("/\d/","",$str);
$fd=fopen("file2.txt","w");
fwrite($fd,$str);
fclose($fd);
*/
/*
// 1,1 sec - 40 MB
$arr = array(0,1,2,3,4,5,6,7,8,9);
$fd=fopen("file1.txt","r");
$str=fread($fd,filesize("file1.txt"));
fclose($fd);
$str=str_replace($arr,'',$str);
$fd=fopen("file2.txt","w");
fwrite($fd,$str);
fclose($fd);
*/
/*
// 0,93 sec - 2200 KB
$arr = array(0,1,2,3,4,5,6,7,8,9);
$fd=fopen("file1.txt","r");
$fd2=fopen("file2.txt","w");
while($str=fread($fd,450000)){
$str=str_replace($arr,'',$str);
fwrite($fd2,$str);
}
fclose($fd);
fclose($fd2);
*/
/*
// 0,93 sec - 88 KB
$arr = array(0,1,2,3,4,5,6,7,8,9);
$fd=fopen("file1.txt","r");
$fd2=fopen("file2.txt","w");
while($str=fread($fd,8000)){
$str=str_replace($arr,'',$str);
fwrite($fd2,$str);
}
fclose($fd);
fclose($fd2);
*/
timer();
$t += $TIMER;
}
echo $t / $N;
?>