The test and analysis of the speed of extracting core function of PHP collection data
Due to the need of the program, the core part of the character extraction in PHP acquisition is tested in the execution speed.
Three of the most common extraction methods were tested:
Method One:
Require "class.debug.php";
function GetContent ($SOURCESTR)
{
$content = Strstr ($sourceStr, ' shape ');
$content = substr ($content, 0, Strrpos ($content, ' words ') + strlen (' words '));
return $content;
}
$SOURCESTR = ' Reject any statement in this forum which contradicts the laws of the People's Republic of China ' in any form;
$debug = new Debug;
$debug->starttimer ();
for ($i = 0; $i < 1000000; $i + +)
{
$RETURNSTR = GetContent ($SOURCESTR);
}
$timeInfo = $debug->endtimer ();
Echo $timeInfo;
?>
Extraction is performed by comparing low-level character manipulation functions.
Method Two:
Require "class.debug.php";
function GetContent ($SOURCESTR)
{
$pattern = "/shape (. *?) Words/is ";
Preg_match_all ($pattern, $SOURCESTR, $result);
return $result [1][0];
}
$SOURCESTR = ' Reject any statement in this forum which contradicts the laws of the People's Republic of China ' in any form;
$debug = new Debug;
$debug->starttimer ();
for ($i = 0; $i < 1000000; $i + +)
{
$RETURNSTR = GetContent ($SOURCESTR);
}
$timeInfo = $debug->endtimer ();
Echo $timeInfo;
?>
Use a simple regular to extract.
Method Three:
Require "class.debug.php";
function GetContent ($SOURCESTR)
{
$content = explode (' shape ', $sourceStr);
$content = explode (' say ', $content [1]);
return $content [0];
}
$SOURCESTR = ' Reject any statement in this forum which contradicts the laws of the People's Republic of China ' in any form;
$debug = new Debug;
$debug->starttimer ();
for ($i = 0; $i < 1000000; $i + +)
{
$RETURNSTR = GetContent ($SOURCESTR);
}
$timeInfo = $debug->endtimer ();
Echo $timeInfo;
?>
Extracted by a two-time explode split string.
Before testing my opinion is: 1 > 2 > 3
http://www.bkjia.com/PHPjc/445171.html www.bkjia.com true http://www.bkjia.com/PHPjc/445171.html techarticle The test and analysis of the speed of the core function of extracting data from PHP is performed in the core part of the character extraction in PHP acquisition because of the need of the program. Tested three kinds of ...