note 93807 deleted from function.parse-ini-file by cmb

From: Date: Sun, 02 Dec 2018 12:49:18 +0000
Subject: note 93807 deleted from function.parse-ini-file by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-209827@lists.php.net to get a copy of this message
Note Submitter: prometheus ---- I made a small test to check differencies between parse_ini_file and json_decode and I surprised a little bit. Here are my test files... parseini-test.ini: [global] a = 1 b = 2 c = "Lorem Ipsum" d = "Dolor Sit Amet" e = 3.14 jsondecode-test.json: { "a": 1, "b": 2, "c": "Lorem Ipsum", "d": "Dolor Sit Amet", "e": 3.14 } And source codes are... parseini.php: <?php $s = microtime(TRUE); for ($i=0; $i<100000; $i++) { $a = parse_ini_file('./parseini-test.ini'); unset($a); } $e = microtime(TRUE); echo $e-$s; ?> jsondecode.php: <?php $s = microtime(TRUE); for ($i=0; $i<100000; $i++) { $a = json_decode(file_get_contents('./jsondecode-test.json'), TRUE); unset($a); } $e = microtime(TRUE); echo $e-$s; ?> These tests ran for three times (the third result is near to average in my experiences): - parseini.php: 3.24759721756 - jsondecode.php: 3.289290905 My conclusion: Im going to use the json_decode() for reading config files because no significant difference in running time between parse_ini_file() and json_decode() + file_get_contents() but JSON is a more powerful format for storing well typed (parse_ini_file parses 3.14 as string, json_decode as float) and well structured configuration settings. As a note: json_decode is sensitive for associative keys quotation, use quotes at all time in keys` names. Test ran on PHP 5.2.

« previous php.notes (#209827) next »