SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    May 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Nesting of functions

    Does nesting of functions have an impact on performance? Is

    $id = mysql_result($result, $i, "id");

    Faster than

    $id = mysql_result(mysql_query(""), $i, "id");

    Am I wrong in assuming that nesting of functions is faster since PHP does not have to allocate memory for the variables returned?

  2. #2
    SitePoint Evangelist djdykes's Avatar
    Join Date
    Feb 2005
    Location
    Chester, Cheshire
    Posts
    565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm never thought of doing it that way... thats pretty cool...
    if it works i'd stick with it... i generally try not to assign variables unnecessarily so i would agree that would maybe be faster...
    however maybe for clarity it would be better to store your query in a separate variable.

  3. #3
    get into it! bigduke's Avatar
    Join Date
    May 2004
    Location
    Australia
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ofcourse you could do that, however the performance improvement will be marginal and this kind of code would increase maintenance hassles.

  4. #4
    SitePoint Guru dbevfat's Avatar
    Join Date
    Dec 2004
    Location
    ljubljana, slovenia
    Posts
    684
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using nested functions in this particular example makes error control harder. Besides, the improvement is probably so small that you'd never notice it.

  5. #5
    SitePoint Member
    Join Date
    May 2005
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are searching some benefits to performance, why not replace double quotation marks with single quotation marks?

    It is more effective.
    Quote Originally Posted by amok3
    Does nesting of functions have an impact on performance? Is

    $id = mysql_result($result, $i, "id");

    Faster than

    $id = mysql_result(mysql_query(""), $i, "id");

    Am I wrong in assuming that nesting of functions is faster since PHP does not have to allocate memory for the variables returned?

  6. #6
    SitePoint Guru dbevfat's Avatar
    Join Date
    Dec 2004
    Location
    ljubljana, slovenia
    Posts
    684
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quotes are no place to improve you performance.

    Let's wrap this up, before it becomes another useless-optimization discussion thread.
    http://www.sitepoint.com/blog-post-view.php?id=240941
    http://www.php.lt/benchmark/phpbench.php
    http://phplens.com/lens/php-book/opt...ugging-php.php

  7. #7
    SitePoint Member
    Join Date
    May 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks everyone


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •