The method for directly returning an array is the slowest.

Source: Internet
Author: User

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

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

1. $ arr. php directly returns an array

<? 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
);
?>

Second, ini. php is the ini file.

<? 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
Thirdly, str. php is the sorted array.

<? 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 ";};
?>

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

$ T1 = microtime (true );

$ File1 =./arr. php;
$ File2 =./ini. php;
$ File3 =./str. php;

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

$ T2 = microtime (true );
Echo $ t2-$ t1;

Result:

Arr. php 5.7820551395416.

Ini. php 5.3364160060883.

Str. php 5.5691919326782

Among them, the fastest ranked is the INI file.

The second is serialization, and the slowest is the direct return array.

Conclusion:

Ini file is good, easy to write (can be considered)

Save the array and use serialization!

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.