Created
May 21, 2010 01:21
-
-
Save katanacrimson/408354 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
obsidian@lithion-mint ~/Documents $ php benchmark.php | |
file - 0.413892 seconds | |
obsidian@lithion-mint ~/Documents $ php benchmark.php | |
file - 0.419085 seconds | |
obsidian@lithion-mint ~/Documents $ php benchmark.php | |
file - 0.428959 seconds | |
obsidian@lithion-mint ~/Documents $ php benchmark.php | |
file - 0.440547 seconds | |
obsidian@lithion-mint ~/Documents $ php benchmark.php | |
file - 0.430267 seconds | |
obsidian@lithion-mint ~/Documents $ php benchmark.php | |
fgets - 1.023405 seconds | |
obsidian@lithion-mint ~/Documents $ php benchmark.php | |
fgets - 0.999376 seconds | |
obsidian@lithion-mint ~/Documents $ php benchmark.php | |
fgets - 0.994365 seconds | |
obsidian@lithion-mint ~/Documents $ php benchmark.php | |
fgets - 1.025741 seconds | |
obsidian@lithion-mint ~/Documents $ php benchmark.php | |
fgets - 0.99858 seconds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C:\xampp\htdocs\Ximps>php tests.php | |
file - 0.310402 seconds | |
C:\xampp\htdocs\Ximps>php tests.php | |
file - 0.309679 seconds | |
C:\xampp\htdocs\Ximps>php tests.php | |
file - 0.314347 seconds | |
C:\xampp\htdocs\Ximps>php tests.php | |
file - 0.310647 seconds | |
C:\xampp\htdocs\Ximps>php tests.php | |
file - 0.311683 seconds | |
C:\xampp\htdocs\Ximps>php tests.php | |
fgets - 6.783487 seconds | |
C:\xampp\htdocs\Ximps>php tests.php | |
fgets - 6.762257 seconds | |
C:\xampp\htdocs\Ximps>php tests.php | |
fgets - 6.929103 seconds | |
C:\xampp\htdocs\Ximps>php tests.php | |
fgets - 6.747566 seconds | |
C:\xampp\htdocs\Ximps>php tests.php | |
fgets - 6.857936 seconds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./blob.php contained 20129 lines of source code.... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$mode = 'fgets'; | |
benchmark(); | |
for($i = 0; $i <= 20; $i++) | |
{ | |
if($mode == 'fgets') | |
getErrorContextFgets('./blob.php', 10000, 4); | |
elseif($mode == 'file') | |
getErrorContextFile('./blob.php', 10000, 4); | |
} | |
echo $mode . ' - '; | |
benchmark(); | |
die(); | |
function getTime() | |
{ | |
$timer = explode(' ', microtime()); | |
return $timer[1] + $timer[0]; | |
} | |
function benchmark() | |
{ | |
static $start = 0; | |
if(!$start) | |
$start = getTime(); | |
else | |
echo round(getTime() - $start, 6) . ' seconds' . PHP_EOL; | |
} | |
function getErrorContextFile($file, $line, $context = 3) | |
{ | |
$return = array(); | |
$content = file($file); | |
for ($i = ($line - $context); $i < (($line -1) + $context); $i++) | |
{ | |
$return[] = $content[$i]; | |
} | |
return $return; | |
} | |
function getErrorContextFgets($file, $line, $context = 3) | |
{ | |
$return = ''; | |
$line_i = 0; | |
if($fh = fopen($file,"r")) | |
{ | |
while (!feof($fh)) | |
{ | |
$line_i++; | |
if($line_i > ($line - $context)) | |
{ | |
if($line_i < ($line + $context)) | |
break; | |
$return[] = fgets($fh); | |
} | |
else | |
{ | |
fgets($fh); | |
} | |
} | |
fclose($fh); | |
} | |
return $return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment