[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Phpgroupware-developers] i++ versus ++i
From: |
Joseph Engo |
Subject: |
Re: [Phpgroupware-developers] i++ versus ++i |
Date: |
Fri, 06 Feb 2004 17:21:54 -0500 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Very intresting ... I will make a note of using preincrements from now
on. I don't think we should change all the code for it, but if you
see something
in a section of code you are working on, might as well go ahead and
change it.
Chris Weiss wrote:
| So I did a benchmark, 100 iteration of 100,000 increments and
averaged them.
| The pre-increment is .004 seconds faster on average on P4 2.24Ghz
using php
| 4.3.1 CLI that comes with Mandrake 9.1.
|
| So there's about a 40 nanosecond difference between the two with
| ++$i
being
| faster.
|
| http://cw.darktech.org/cw/test.phps
|
| You might also be interested to know that if I didn't preload $i to
|
100000 in
| a loop first it adds .003 seconds to the first loop.
|
| Chris Weiss (address@hidden) wrote:
|
|> http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40 "echo
|> is marginally faster since it doesn't set a return value if you
|> really want to get down to the nitty gritty."
|>
|> I don't see any mention of speed difference in
|> http://us2.php.net/language.operators.increment. If there are
really found to
|> be the data should be posted there. It's quite possible though
|> that
will be
|> no difference. Where is compiled the temp var is needed, but
|> sine
php is
|> interpreted it's possible that internanly there is a temp var in
both cases.
|>
|>
|> Joseph Engo (address@hidden) wrote:
|>
| Well, first off that page is for C++. I am not sure if the same
| applys to PHP or not. It would be interesting to research.
|
| This is the first I am hearing about echo vs print. Honestly, what
| are the differences if any ? I have personally used echo since I
| started in PHP. Why ? I don't know, I guess to be different from
| the other languages I use.
|
| Joseph Engo
|
| Chris Weiss wrote:
|
| |noted. IMO not worth chnaging old code unless you're redoing that
| area |anyway. It's very a minimal cost (kind of like echo vs
| print) and changing it |any places where it's used inline will
| intruduce bugs. | |Kai Hofmann (address@hidden) wrote: |
| |>Just for info, why it is better to use ++$i instead of $i++ |>
| |>source: http://www.gotw.ca/gotw/002.htm |> |>Preincrement is more
| efficient than postincrement, because for postincrement |>the
| object must increment itself and then return a temporary containing
| its |>old value. Note that this is true even for builtins like int!
| |> |>[Guideline] Prefer preincrement, avoid postincrement. |> |>
| |> |>Have a happy weekend. |> |> Kai/PowerStat |> |>-- |>*****
| Open Source und Linux im professionellen Einsatz ***** |>**
| komplexe Mailserver, Groupware, Office: sprechen Sie uns an **
| |>Dipl.-Inform. Kai Hofmann Team
| Softwarelösungen |>pro|business AG, EXPO Plaza 1 (Deutscher
| Pavillon), 30539 Hannover |>E-Mail: address@hidden,
| Tel.: 0511/60066-332, Fax: -355 |>WWW: http://www.probusiness.de/
| |> |> |> |>_______________________________________________
| |>Phpgroupware-developers mailing list
| |>address@hidden
| |>http://mail.gnu.org/mailman/listinfo/phpgroupware-developers |> |
| | | |_______________________________________________
| |Phpgroupware-developers mailing list
| |address@hidden
| |http://mail.gnu.org/mailman/listinfo/phpgroupware-developers
|
|
_______________________________________________
Phpgroupware-developers mailing list
address@hidden
http://mail.gnu.org/mailman/listinfo/phpgroupware-developers
|>
|>
|> _______________________________________________
|> Phpgroupware-developers mailing list
|> address@hidden
|> http://mail.gnu.org/mailman/listinfo/phpgroupware-developers
|>
| _______________________________________________
| Phpgroupware-developers mailing list
| address@hidden
| http://mail.gnu.org/mailman/listinfo/phpgroupware-developers
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFAJBOB/AzmiD/o0voRAsfoAJoDwWIPLcLC51KwLMmCLn6DXDehdwCgk9r+
qDYC7kCduVzNykp/dCxy/sc=
=7gYc
-----END PGP SIGNATURE-----