Comparison between self-Written string processing and built-in TP Running Efficiency

Source: Internet
Author: User

Self-written:

<? Php $ t1 = microtime (true); function SqlFormat ($ string) {$ Fstr = ''; $ strArr = explode (" _ ", $ string ); foreach ($ strArr AS $ key => $ val) {if ($ key! = 0) {$ Fstr. = ucfirst ($ val);} else {continue;} return (string) $ Fstr;} echo SqlFormat ('dede _ member_feed '); $ t2 = microtime (true ); echo ($ t2-$ t1) * 1000; // running Duration: 0.01 ~ 0.02?>

THINKPHP built-in:

<? Php $ t1 = microtime (true); function parse_name ($ name, $ type = 0) {if ($ type) {return ucfirst (preg_replace ("/_ ([a-zA-Z])/e", "strtoupper ('\ 1')", $ name ));} else {return strtolower (trim (preg_replace ("/[A-Z]/", "_ \ 0", $ name ),"_"));}} echo parse_name ('dede _ member_feed ', 1); $ t2 = microtime (true); echo ($ t2-$ t1) * 1000; // running Duration: 0.03 ~ 0.05?>

All of the above processes the string naming style;

This article from the "against the wind" blog, please be sure to keep this source http://windchaser.blog.51cto.com/5742634/1296502

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.