note 93807 added to function.parse-ini-file

From: Date: Wed, 30 Sep 2009 16:32:03 +0000
Subject: note 93807 added to function.parse-ini-file
Groups: php.notes 
Request: Send a blank email to php-notes+get-161178@lists.php.net to get a copy of this message
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. ---- Server IP: 92.43.200.200 Probable Submitter: 89.132.188.89 ---- Manual Page -- http://www.php.net/manual/en/function.parse-ini-file.php Edit -- https://master.php.net/note/edit/93807 Del: integrated -- https://master.php.net/note/delete/93807/integrated Del: useless -- https://master.php.net/note/delete/93807/useless Del: bad code -- https://master.php.net/note/delete/93807/bad+code Del: spam -- https://master.php.net/note/delete/93807/spam Del: non-english -- https://master.php.net/note/delete/93807/non-english Del: in docs -- https://master.php.net/note/delete/93807/in+docs Del: other reasons-- https://master.php.net/note/delete/93807 Reject -- https://master.php.net/note/reject/93807 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161178) next »