Home  >  Article  >  Backend Development  >  Testing and Analysis of the Speed ​​of PHP Data Collection and Extraction Core Function_PHP Tutorial

Testing and Analysis of the Speed ​​of PHP Data Collection and Extraction Core Function_PHP Tutorial

WBOY
WBOYOriginal
2016-07-20 11:04:57941browse

Testing and analysis of the speed of the core function of PHP collection data extraction
Due to program needs, the execution speed of the core part of character extraction in PHP collection was tested.
Tested the three most common extraction methods:
Method 1:
require "class.debug.php";
function getContent ( $sourceStr )
{
$content = strstr( $sourceStr, 'Shape' );
$content = substr( $content, 0, strrpos( $content, 'Word' ) + strlen( 'Word' ) );
return $content;
}
$sourceStr = 'Reject anyone to make any comments in this forum that conflict with the laws of the People's Republic of China';
$debug = new Debug;
$ debug->startTimer();
for( $i = 0; $i < 1000000; $i++ )
{
$returnStr = getContent( $sourceStr );
}
$timeInfo = $debug->endTimer();
echo $timeInfo;
?>
Extract through relatively low-level character manipulation functions.
Method 2:
require "class.debug.php";
function getContent ( $sourceStr )
{
$pattern = "/shape(.*?)yan/is";
preg_match_all( $pattern, $sourceStr, $result );
return $result[1][0];
}
$sourceStr = 'Reject anyone to publish in this forum any form that is inconsistent with the laws of the People's Republic of China Contradictory remarks';
$debug = new Debug;
$debug->startTimer();
for( $i = 0; $i < 1000000; $i++ )
{
$returnStr = getContent( $sourceStr );
}
$timeInfo = $debug->endTimer();
echo $timeInfo;
?>
Use a simple Regular extraction.
Method 3:
require "class.debug.php";
function getContent ( $sourceStr )
{
$content = explode( 'Shape', $sourceStr );
$content = explode( 'Yan', $content[1] );
return $content[0];
}
$sourceStr = 'Reject any People make any comments in this forum that conflict with 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 ;
?>
Extract by splitting the string twice with explode.
My view before testing is: 1 > 2 > 3

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445171.htmlTechArticleTesting and analyzing the speed of the core function of PHP collection data extraction. Due to program needs, the characters in PHP collection are The extracted core part was tested for execution speed. Tested three...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn