<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1036946" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1036946</link>
    <description></description>
    <language>en</language>
          <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/php-number-formating#comment-1212279</link>
    <description> &lt;p&gt;Whoaaaaaaa. Thanks for all that. It&#039;s gonna take me a while to get my head round it, but every nanosecond I can save is good as far as I&#039;m concerned &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/big.png&quot; title=&quot;Laughing out loud&quot; alt=&quot;Laughing out loud&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Thanks again guys!&lt;/p&gt;
 </description>
     <pubDate>Sun, 17 Dec 2006 13:40:08 +0000</pubDate>
 <dc:creator>andy206uk</dc:creator>
 <guid isPermaLink="false">comment 1212279 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/php-number-formating#comment-1212259</link>
    <description> &lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;p&gt;&lt;strong&gt;JeevesBond;212256 wrote:&lt;/strong&gt; Well this is all a bit weird. I thought anything inside single quotes was a literal, so assumed processing time would be less.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;See, now that&#039;s what I thought too, since variable and other fancy things are processed in double quotes, right?  I have no idea why it turns out faster for me.  I thought maybe my system load changed or something, but it seems not to be the case.  &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/confused.png&quot; title=&quot;Confused&quot; alt=&quot;Confused&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
&lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;p&gt;&lt;strong&gt;JeevesBond;212256 wrote:&lt;/strong&gt; It&#039;s interesting that you managed to optimise that code Abhishek. Wonder how many processor cycles are wasted in the world every day?&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Comparatively, not many are wasted like this.  These optimisations are implementation-specific, systemic tweaks that adjust the algorithm&#039;s growth by small constants.  Many more cycles are wasted when people choose an inefficient algorithm in the first place, optimised or not.  &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/sad.png&quot; title=&quot;Sad&quot; alt=&quot;Sad&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
&lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;p&gt;&lt;strong&gt;JeevesBond;212256 wrote:&lt;/strong&gt; Only slight flaw with the numeric comparison is that you&#039;re assuming that variable is a number. What would happen if it were a marmot? Or a duck? Then you&#039;d be in trouble. &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Uhmm... I&#039;d &lt;em&gt;duck&lt;/em&gt;ument it carefully and blame the quack who sent the bad inputs!  &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/tongue.png&quot; title=&quot;Sticking out tongue&quot; alt=&quot;Sticking out tongue&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Seriously.  One only optimises like this once all the interfaces/protocols are stable.  I assumed Andy knew for sure that he had an array of integers.&lt;/p&gt;
&lt;p&gt;In case of an error, an exception ought to be thrown and caught, anyway.  Like an UnexpectedMarmotException.  Or something.  &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/tongue.png&quot; title=&quot;Sticking out tongue&quot; alt=&quot;Sticking out tongue&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
&lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;p&gt;&lt;strong&gt;JeevesBond;212256 wrote:&lt;/strong&gt; What figure do you use for the timing? &#039;real&#039;, &#039;user&#039; or &#039;sys&#039;?&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Real.&lt;/p&gt;
&lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;p&gt;&lt;strong&gt;JeevesBond;212256 wrote:&lt;/strong&gt; Was messing around with this test too. Am getting pretty similar results to you: I seem to have a smaller array though. What did you do to get such a gigantic set of numbers? &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;I generated the sequence using two loops in Emacs.  Wasn&#039;t aiming for 1.5MB, that was arbitrary.  Could have used range() in PHP too.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
 </description>
     <pubDate>Sun, 17 Dec 2006 08:59:32 +0000</pubDate>
 <dc:creator>Abhishek Reddy</dc:creator>
 <guid isPermaLink="false">comment 1212259 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/php-number-formating#comment-1212256</link>
    <description> &lt;p&gt;Well this is all a bit weird. I thought anything inside single quotes was a literal, so assumed processing time would be less. Suppose most PHP applications I&#039;ve seen have used double-quotes so must be wrong!&lt;/p&gt;
&lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;p&gt;&lt;strong&gt;Abhishek wrote:&lt;/strong&gt; I would have guessed that sprintf was more efficient.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt; So would I for the same reasons!&lt;/p&gt;
&lt;p&gt;It&#039;s interesting that you managed to optimise that code Abhishek. Wonder how many processor cycles are wasted in the world every day? Hmmm, thinking like that will probably make me go insane. &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Only slight flaw with the numeric comparison is that you&#039;re assuming that variable is a number. What would happen if it were a marmot? Or a duck? Then you&#039;d be in trouble. &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
&lt;p&gt;*** EDIT ***&lt;br /&gt;
What figure do you use for the timing? &#039;real&#039;, &#039;user&#039; or &#039;sys&#039;?&lt;/p&gt;
&lt;p&gt;Was messing around with this test too. Am getting pretty similar results to you: I seem to have a smaller array though. What did you do to get such a gigantic set of numbers? &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
 </description>
     <pubDate>Sun, 17 Dec 2006 08:03:09 +0000</pubDate>
 <dc:creator>JeevesBond</dc:creator>
 <guid isPermaLink="false">comment 1212256 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/php-number-formating#comment-1212250</link>
    <description> &lt;p&gt;Using double quotes instead of single quotes cuts it further:&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;if(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;&amp;lt; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;10 &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;sprintf&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(\&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;%02s\&quot;,&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;);&lt;br /&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;br /&gt;
has a mean of &lt;strong&gt;158 ms&lt;/strong&gt; and s.d. 3.18 ms.&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;if(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;&amp;lt; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;10 &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= \&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;0\&quot;.&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;;&lt;br /&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;br /&gt;
has a mean of &lt;strong&gt;157 ms&lt;/strong&gt; and s.d. 3.36 ms.&lt;/p&gt;
&lt;p&gt;Sorry if this is more than you wanted to know!  I&#039;m curious to see just how much this can be optimised.  I&#039;d say this is nearing the limit, though.  &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
 </description>
     <pubDate>Sun, 17 Dec 2006 04:34:45 +0000</pubDate>
 <dc:creator>Abhishek Reddy</dc:creator>
 <guid isPermaLink="false">comment 1212250 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/php-number-formating#comment-1212249</link>
    <description> &lt;p&gt;Okay, seems a lot of the overhead in the conditional ones is from the [incode]strlen[/incode] call.  Numeric comparison is faster:&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;if(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;&amp;lt; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;10 &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;sprintf&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;%02s&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;); &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;br /&gt;
has a mean of &lt;strong&gt;169 ms&lt;/strong&gt; and s.d. 3.81 ms.&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;if(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;&amp;lt; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;10 &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;0&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;br /&gt;
has a mean of &lt;strong&gt;163 ms&lt;/strong&gt; and s.d. of 3.81 ms.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
 </description>
     <pubDate>Sun, 17 Dec 2006 04:16:42 +0000</pubDate>
 <dc:creator>Abhishek Reddy</dc:creator>
 <guid isPermaLink="false">comment 1212249 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/php-number-formating#comment-1212233</link>
    <description> &lt;p&gt;I would have guessed that [incode]sprintf[/incode] was more efficient.  It&#039;s a call to what should be a compiled (native?) function, rather than an interpreted block.  And the PHP implementation also has the opportunity to optimise it in other ways that would be tricky in user code.&lt;/p&gt;
&lt;p&gt;However, sprintf appears to be slower.  I ran a quick set of tests timing both methods on a large (1.5MB) array, from the PHP command line.  I used PHP 5.1.6/Zend on GNU/Linux.&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;$a &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= array(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;3 &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;... &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;200&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;3 &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;... &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;200 &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;...);&lt;br /&gt;foreach (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$a &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;as &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;) {&lt;br /&gt;&amp;nbsp; if (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;strlen&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;) == &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;0&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;//conditional dot&lt;br /&gt;&amp;nbsp; // or:&lt;br /&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;sprintf&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;%02s&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;//sprintf&lt;br /&gt;&amp;nbsp; //or:&lt;br /&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;if (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;strlen&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;) == &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;sprintf&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;%02s&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$v&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;//conditional sprintf&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;Executed with:&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;$ time php /path/to/sprintf-profile.php&lt;/code&gt;&lt;/div&gt;&#039;&lt;/p&gt;
&lt;p&gt;Results for 20 runs each:&lt;br /&gt;
[incode]sprintf[/incode]: mean of &lt;strong&gt;235 ms&lt;/strong&gt; and s.d. of 3.54 ms.&lt;br /&gt;
conditional [incode]sprintf[/incode]: mean of &lt;strong&gt;199 ms&lt;/strong&gt; and s.d. of 3.82 ms. [Edit: fixed typo.]&lt;br /&gt;
conditional dot: mean of &lt;strong&gt;197 ms&lt;/strong&gt; and s.d. of 4.86 ms.&lt;/p&gt;
&lt;p&gt;I think the dot syntax is more heavily optimised, and calling [incode]sprintf[/incode] is not cheap anyway.&lt;/p&gt;
&lt;p&gt;Of course, this isn&#039;t a particularly good test, as it may depend on what platform, PHP version and extensions you run.  And my input array could probably be better.  And this doesn&#039;t say anything about growth.&lt;/p&gt;
&lt;p&gt;You might like to try it on your host machine too, with the kind of data you expect, before making a decision.&lt;/p&gt;
&lt;p&gt;In any case, the difference isn&#039;t huge.  I&#039;d go with [incode]sprintf[/incode] because I find it more readable.  It&#039;s probably not worth saving 40 ms here.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
 </description>
     <pubDate>Sun, 17 Dec 2006 02:44:54 +0000</pubDate>
 <dc:creator>Abhishek Reddy</dc:creator>
 <guid isPermaLink="false">comment 1212233 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/php-number-formating#comment-1212230</link>
    <description> &lt;p&gt;Thanks Jeeves, if nothing else it&#039;s shrunk my code down from 5 lines to one! &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/big.png&quot; title=&quot;Laughing out loud&quot; alt=&quot;Laughing out loud&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
 </description>
     <pubDate>Sat, 16 Dec 2006 22:55:32 +0000</pubDate>
 <dc:creator>andy206uk</dc:creator>
 <guid isPermaLink="false">comment 1212230 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/php-number-formating#comment-1212227</link>
    <description> &lt;p&gt;Well either way your going to have to convert a number to a string, a better method might be to use &lt;a href=&quot;http://www.php.net/manual/en/function.sprintf.php&quot; class=&quot;bb-url&quot;&gt;sprintf&lt;/a&gt;. For example:&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;$value &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;sprintf&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;%02s&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$value&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;br /&gt;
number_format is for decimal points and thousand seperators (as far as I can tell), probably why you can&#039;t work out how to use it for what you want to do. More of those esoteric PHP function names, you&#039;d think that number_format should do what you need. &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
&lt;p&gt;sprintf comes from c, in case anyone&#039;s interested.&lt;/p&gt;
 </description>
     <pubDate>Sat, 16 Dec 2006 22:24:57 +0000</pubDate>
 <dc:creator>JeevesBond</dc:creator>
 <guid isPermaLink="false">comment 1212227 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/php-number-formating#comment-1212225</link>
    <description> &lt;p&gt;ok... I worked out a way to do it (without number_format - see below), but I have a feeling it&#039;s really inefficient - especially because I have to repeat this several times when I loop through an array.&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;if(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;strlen&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$value&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;) == &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;) {&lt;br /&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$value &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;0&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$value&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;Do you think this will be ok, or would the number_format way be better? I need the function it&#039;s in to be as efficient as possible as it&#039;s the backbone of the whole project and could potentially see a lot of traffic.&lt;/p&gt;
&lt;p&gt;Any help would be really appreciated &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/big.png&quot; title=&quot;Laughing out loud&quot; alt=&quot;Laughing out loud&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
 </description>
     <pubDate>Sat, 16 Dec 2006 21:39:19 +0000</pubDate>
 <dc:creator>andy206uk</dc:creator>
 <guid isPermaLink="false">comment 1212225 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
