The PHP function returns the slowest array directly.

Source: Internet
Author: User

Cached files. The most commonly used estimation is return array ();

Www.phperz.com

Experiments show that this method is slow. Test the following three files.

WWW ~ Phperz ~ Com

1. $ arr. php directly returns an array of PHP programmers

<? PHP
Return Array
(
& Quot; db_host1 & quot; = & quot; 123,
"Db_host2" => 123,
"Db_host3" => 123,
"Db_host4" => 123,
"Db_host5" => 123,
"Db_host6" => 123,
"Db_host7" => 123,
"Db_host8" => 123,
"Db_host9" => 123,
"Db_host10" => 123,
"Db_host11" => 123,
"Db_host12" => 123,
"Db_host13" => 123,
"Db_host14" => 123,
"Db_host15" => 123,
"Db_host16" = & gt; 123
);
?>

WWW ~ Phperz ~ Com

Second, INI. php is the INI file.

Www.phperz.com

<? PHP exit;?>
Db_host1 = 123
Db_host2 = 123
Db_host3 = 123
Db_host 4 = 123
Db_host5 = 123
Db_host6 = 123
Db_host7 = 123
Db_host8 = 123
Db_host9 = 123
Db_host10 = 123
Db_host11 = 123
Db_host12 = 123
Db_host13 = 123
Db_host14 = 123
Db_host15 = 123
Db_host16 = 123
Third, str. php is the sorted array phperz.com.

<? PHP
Return
'A: 16: {s: 8: "db_host1"; s: 3: "123"; s: 8: "db_host2"; s: 3: "123"; s: 8: "db_host3"; s: 3: "123"; s: 8: "db_host4"; s: 3: "123"; s: 8: "db_host5"; s: 3: "123"; s: 8: "db_host6"; s: 3: "123"; s: 8: "db_host7"; s: 3: "123"; s: 8: "db_host8"; s: 3: "123"; s: 8: "db_host9"; s: 3: "123"; s: 9: "db_host10"; s: 3: "123"; s: 9: "db_host11"; s: 3: "123"; s: 9: "db_host12"; s: 3: "123"; s: 9: "db_host13"; s: 3: "123"; s: 9: "db_host14"; s: 3: "123"; s: 9: "db_host15"; s: 3: "123"; s: 9: "db_host16"; s: 3: "123 ";}';
?>

PHP programmer's house

Perform a 10000-containing array test on the three files, respectively.

Phperz.com

$ T1 = microtime (true );

Www.phperz.com

$ File1 = './ARR. php ';
$ File2 = './INI. php ';
$ File3 = './Str. php'; PHP programmer site

For ($ I = 0; I I <10000; $ I ++ ){
// $ Arr = require $ file1;
// $ Arr = parse_ini_file ($ file2 );
$ Arr = unserialize (require $ file3 );
} PHP programmer site

$ T2 = microtime (true );
Echo $ t2-$ T1; www ~ Phperz ~ Com

Result:

Phperz.com

Arr. php 5.7820551395416.

PHP programmer's house

INI. php 5.3364160060883.

Phperz ~ Com

Str. php 5.5691919326782 www.phperz.com

Among them, the fastest ranked is the INI file.

WWW ~ Phperz ~ Com

The second is serialization, and the slowest is the direct return array WWW ~ Phperz ~ Com

Conclusion:

PHP programmer's house

INI file is good, easy to write (can be considered) PHP programmer's house

Save the array and use serialization! PHP programmer site

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.