search
Homephp教程php手册php函数直接返回数组的方法是最慢的

缓存文件,大家用的最多的估计就是 return array(); www.phperz.com 实验证明,这种方法是较慢的,试考查以下的3个文件. www~phperz~com 其一. $arr.php 直接返回 数组 php程序员之家 ?php return Array ( "db_host1" = 123, "db_host2" = 123, "db_host3" = 12

缓存文件,大家用的最多的估计就是 return array();

www.phperz.com

实验证明,这种方法是较慢的,试考查以下的3个文件.

www~phperz~com

其一. $arr.php 直接返回 数组 php程序员之家

return Array
(
    "db_host1" => 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" => 123
);
?>

www~phperz~com

其二,  ini.php 为INI文件

www.phperz.com


db_host1 =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 =123
其三,str.php 为序例化后的数组 phperz.com

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程序员之家

分别对3个文件  进行10000次包含返回数组测试

phperz.com

$t1 = microtime(true);

www.phperz.com

$file1 = './arr.php';
$file2 = './ini.php';
$file3 = './str.php'; php程序员站

for($i=0; $i//$arr  = require $file1;
//$arr  = parse_ini_file($file2);
$arr  = unserialize(require $file3);
} php程序员站

$t2 = microtime(true);
echo $t2-$t1; www~phperz~com

得出结果:

phperz.com

arr.php       5.7820551395416

php程序员之家

ini.php        5.3364160060883

phperz~com

str.php        5.5691919326782 www.phperz.com

其中,排得最快的居然是 INI文件.

www~phperz~com

其次是序列化, 最慢的是直接 return 数组 www~phperz~com

结论:

php程序员之家

   ini 文件不错,方便书写(可以考虑) php程序员之家

   保存数组, 用序列化! php程序员站

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!