note 79469 added to function.vprintf

From: Date: Thu, 29 Nov 2007 01:38:28 +0000
Subject: note 79469 added to function.vprintf
Groups: php.notes 
Request: Send a blank email to php-notes+get-132647@lists.php.net to get a copy of this message
For blocks of text, sprintf() is slow according to my tests. Also, having the mapping between place-holders and the list of actual variables or datastructures often makes this code difficult to read. But the printf() family are widely supported and have a huge range of nice features. Performance is a cold mistress though! From an ease-of-reading and maintenance, debugging point of view, I much prefer HEREDOC and "...{$variable}..." methods. For a block of HTML markup with place holders, the fastest by far was:- ?> <div> markup etc<?= $variable ?>more markup <? My tests comprised 20 runs of a loop of 1 million iterations with output buffering, ditching the buffer on each loop. The timings ranged from average 2.1msec/million repetitions for the <?= $var ?> method up to 7.6msec/million using printf(). I'll try some benchmarking tools too, since I just wrote this myself and it could be introducing bias, but they've run on dev servers with low load. Hopefully interesting. ---- Server IP: 202.89.58.1 Probable Submitter: 125.236.204.9 ---- Manual Page -- http://www.php.net/manual/en/function.vprintf.php Edit -- https://master.php.net/note/edit/79469 Del: integrated -- https://master.php.net/note/delete/79469/integrated Del: useless -- https://master.php.net/note/delete/79469/useless Del: bad code -- https://master.php.net/note/delete/79469/bad+code Del: spam -- https://master.php.net/note/delete/79469/spam Del: non-english -- https://master.php.net/note/delete/79469/non-english Del: in docs -- https://master.php.net/note/delete/79469/in+docs Del: other reasons-- https://master.php.net/note/delete/79469 Reject -- https://master.php.net/note/reject/79469 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#132647) next »