mirror of
https://github.com/leonelquinteros/php-toml.git
synced 2025-01-17 12:28:16 +01:00
Improve performance of loops. Precalculate limit.
This commit is contained in:
parent
a56504f310
commit
66b7720028
@ -141,7 +141,8 @@ class Toml
|
||||
$openBrackets = 0;
|
||||
$openString = false;
|
||||
|
||||
for($i = 0; $i < strlen($toml); $i++)
|
||||
$strLen = strlen($toml);
|
||||
for($i = 0; $i < $strLen; $i++)
|
||||
{
|
||||
$keep = true;
|
||||
|
||||
@ -287,7 +288,8 @@ class Toml
|
||||
$openString = false;
|
||||
$buffer = '';
|
||||
|
||||
for($i = 0; $i < strlen($val); $i++)
|
||||
$strLen = strlen($val);
|
||||
for($i = 0; $i < $strLen; $i++)
|
||||
{
|
||||
if($val[$i] == '[' && !$openString)
|
||||
{
|
||||
|
@ -9,7 +9,7 @@ $result = Toml::parseFile('extended.toml');
|
||||
|
||||
$one = microtime(true);
|
||||
|
||||
echo "\nTooks " . (($one - $start) * 1000) . "s to parse 1 file";
|
||||
echo "\nTooks " . ($one - $start) . "s to parse 1 file";
|
||||
echo "\nMemory usage at this point: " . memory_get_usage();
|
||||
|
||||
|
||||
@ -22,19 +22,19 @@ for($i = 0; $i < 1000; $i++)
|
||||
|
||||
$thousand = microtime(true);
|
||||
|
||||
echo "\nTooks " . (($thousand - $start) * 1000) . "s to parse 1000 times the same file";
|
||||
echo "\nTooks " . ($thousand - $start) . "s to parse 1000 times the same file";
|
||||
echo "\nMemory usage at this point: " . memory_get_usage();
|
||||
|
||||
|
||||
$start = microtime(true);
|
||||
|
||||
for($i = 0; $i < 100000; $i++)
|
||||
for($i = 0; $i < 10000; $i++)
|
||||
{
|
||||
$result = Toml::parseFile('extended.toml');
|
||||
}
|
||||
|
||||
$thousand = microtime(true);
|
||||
|
||||
echo "\nTooks " . (($thousand - $start) * 1000) . "s to parse 100.000 times the same file";
|
||||
echo "\nTooks " . ($thousand - $start) . "s to parse 10.000 times the same file";
|
||||
echo "\nMemory usage at this point: " . memory_get_usage();
|
||||
echo "\n";
|
||||
|
Loading…
x
Reference in New Issue
Block a user