Test and analyze the speed of PHP core functions for data extraction. Test and analysis on the speed of the core function for extracting PHP Data, and test the execution speed of the core part of the character extraction in PHP collection because of the program's needs. Testing and analyzing the speed of three core functions for PHP Data Extraction
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:
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:
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:
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
Because of program requirements, the execution speed of the core part of character extraction in PHP collection is tested. Three types...