Test and analysis of the speed of extracting core function from PHP data acquisition

Source: Internet
Author: User
Tags explode
Test and analysis of the speed of extracting core function from PHP data acquisition
As a result of the program needs, the PHP acquisition of character extraction in the core of the implementation of the speed test.
Three of the most common extraction methods were tested:
Method One:
<?php
Require "class.debug.php";
function GetContent ($SOURCESTR)
{
$content = Strstr ($sourceStr, ' form ');
$content = substr ($content, 0, Strrpos ($content, ' say ') + strlen (' speech '));
return $content;
}
$SOURCESTR = ' Deny any person any form of speech in this forum which is inconsistent 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;
?>
Extracted by comparing the low-level character manipulation functions.
Method Two:
<?php
Require "class.debug.php";
function GetContent ($SOURCESTR)
{
$pattern = "/shape (. *?) Words/is ";
Preg_match_all ($pattern, $SOURCESTR, $result);
return $result [1][0];
}
$SOURCESTR = ' Deny any person any form of speech in this forum which is inconsistent 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;
?>
Use a simple regular to extract.
Method Three:
<?php
Require "class.debug.php";
function GetContent ($SOURCESTR)
{
$content = explode (' shape ', $sourceStr);
$content = Explode (' speech ', $content [1]);
return $content [0];
}
$SOURCESTR = ' Deny any person any form of speech in this forum which is inconsistent 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;
?>
Extracted by two times explode splitting string.
Before the test my opinion is: 1 > 2 > 3

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.