Test and Analysis of the speed at which PHP collects data to extract core functions

Source: Internet
Author: User

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

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.