2

I wonder what is faster:

  • loading/including a php file that contains some static data in an array within a function or
  • parsing an ini-file that contains the data and puts it into an arary

I need that to know for my config files and some of them can be really big.

EDIT:

I tested it now with an array and an ini-file with 10.000 values each and came to the following result:

  • Static Data took 0.0072767734527588 to complete
  • INI file took 0.01829195022583 to load and parse
4

4 回答 4

2

这将计算处理这两个文件/数据集的每一个所需的时间。

function staticDataCalc()
{
    $start = microtime(true);

    /** LOAD AND PARSE YOUR PHP FILE WITH STATIC DATA **/

    $end = microtime(true);
    $totalTimeTaken = $end - $start;

    echo 'Static Data took ' . $totalTimeTaken . ' to complete';
}


function iniFileCalc()
{
    $start = microtime(true);

    /** LOAD AND PARSE YOUR INI FILE **/

    $end = microtime(true);
    $totalTimeTaken = $end - $start;

    echo 'INI file took ' . $totalTimeTaken . ' to load and parse';
}

echo staticDataCalc() . '<br />';
echo iniFileCalc();
于 2013-05-17T10:27:40.930 回答
2

我将放弃对 PHP ini 的赞许...由于以下几点..

  1. 将单个文件与其他语言(如 Perl、Python、Ruby 等)一起使用。
  2. 数据编辑。 INI 格式远没有 PHP 代码那么可怕,即使只是一堆变量声明

  3. 易于更新设置。 我认为创建一个新的 INI 文件比编写一个 PHP 文件要容易得多。

  4. 易于建立设置变量之间的关系。 使用 INI 文件为您的设置提供层次结构很容易。虽然使用 PHP 也可以做到这一点,但如果您尝试使用深度嵌套的关联数组来存储信息,那么它就不那么整洁并且可能会变得难看。

于 2013-05-17T10:45:12.387 回答
0

如果您需要它进行全局配置,那么创建一个带有数组的文件并使用函数获取它的值并将键作为参数传递会比ini文件更好更快。

于 2013-05-17T10:28:46.703 回答
0

使用字节码缓存,包含 php 文件会更快。

于 2013-05-17T10:29:04.040 回答