Testing and analyzing the speed of extracting core function of PHP data collection _php Tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.