Test and analysis on the speed of collecting PHP Data to extract core functions _ PHP Tutorial

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

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.