Test and Analysis of the speed at which PHP collects data to extract core functions
As the program requires, the execution speed of the core part of character extraction in PHP collection is tested.
Three Common extraction methods are tested:
Method 1:
<? Php
Require "class. debug. php ";
Function getContent ($ sourceStr)
{
$ Content = strstr ($ sourceStr, '');
$ Content = substr ($ content, 0, strrpos ($ content, 'yan') + strlen ('yan '));
Return $ content;
}
$ SourceStr = 'Deny anyone to post any comments in this forum that contradict the laws of the People's Republic of China in any form ';
$ Debug = new Debug;
$ Debug-> startTimer ();
For ($ I = 0; I I <1000000; $ I ++)
{
$ ReturnStr = getContent ($ sourceStr );
}
$ TimeInfo = $ debug-> endTimer ();
Echo $ timeInfo;
?>
Extraction by relatively low-level character operation functions.
Method 2:
<? Php
Require "class. debug. php ";
Function getContent ($ sourceStr)
{
$ Pattern = "/shape (.*?) Statement/is ";
Preg_match_all ($ pattern, $ sourceStr, $ result );
Return $ result [1] [0];
}
$ SourceStr = 'Deny anyone to post any comments in this forum that contradict the laws of the People's Republic of China in any form ';
$ Debug = new Debug;
$ Debug-> startTimer ();
For ($ I = 0; I I <1000000; $ I ++)
{
$ ReturnStr = getContent ($ sourceStr );
}
$ TimeInfo = $ debug-> endTimer ();
Echo $ timeInfo;
?>
Use a simple regular expression for extraction.
Method 3:
<? Php
Require "class. debug. php ";
Function getContent ($ sourceStr)
{
$ Content = explode ('', $ sourceStr );
$ Content = explode ('yan', $ content [1]);
Return $ content [0];
}
$ SourceStr = 'Deny anyone to post any comments in this forum that contradict the laws of the People's Republic of China in any form ';
$ Debug = new Debug;
$ Debug-> startTimer ();
For ($ I = 0; I I <1000000; $ I ++)
{
$ ReturnStr = getContent ($ sourceStr );
}
$ TimeInfo = $ debug-> endTimer ();
Echo $ timeInfo;
?>
Extract the string by splitting the explode twice.
My opinion before the test is: 1> 2> 3