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
0

4 Answers 4

2

This will calculate how long it took to process each of the two files / datasets.

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();
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your "testmodule". I tested it and came to the following result: Static Data took 0.0072767734527588 to complete, INI file took 0.01829195022583 to load and parse :)
Which would suggest loading the static data took 0.01 seconds faster to load :)
2

I will give up-thumb to PHP ini...Due to below points..

  1. Use single file with other language(like Perl, Python, Ruby, etc.).
  2. Editing of data. The INI format is a lot less scary than PHP code, even if it is just a bunch of variable declarations

  3. Easy to Update the settings. I think it is much easier to create a new INI file rather than writing a PHP file.

  4. Easy to make Relationship between setting variables. It is easyto give your settings a hierarchy with a INI file. While this would also be possible with PHP it is not as neat and can get unsightly if you are trying to do deeply nested associative arrays to store information.

1 Comment

ad 1: i just use it for php and according my question only php is relative; ad 2 & 3: i think that does not matter :) ; ad 4: well, in most cases you won't use "deeply nested associative arrays" for a config-file i think...
0

If you need this for global configuration then creating a file with array and fetching it value using function and passing key as parameter will be good and faster then ini-file.

Comments

0

With bytecode cache it would be faster to include php file.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.