#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    14
    Rep Power
    0
    Hello,
    Which solution is the best through the web?
    $str= '' ;
    For($i=0 ; $i<100 ; $i++)
    $str.= 'aaaaaaaaaaa bbbb ccccccc' ;
    printf('%s', $str) ;

    or
    $str.= 'aaaaaaaaaaa bbbb ccccccc' ;
    For($i=0 ; $i<100 ; $i++)
    printf('%s', $str) ;

    Thank you
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    27
    Rep Power
    0
    They are identical - they are each 4 lines long, just written in different styles (the 3-lined code is really the same as the other because of it's declaration: $str.='' [this is because of the '.' which adds an extra action for the processor to do])...

    but the important thing to realize is that worrying about the efficiency of 4 lines (let alone a web program consisting of... say 1-or 200 lines) is not necessary; the servers will process good code and not-so-good code in the same relative time (no humanly-noticable difference). ...Now ineffieient recursion, that's a different story...

    Just write whatever you're most comfortable with.

    //ryan
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    51
    Rep Power
    14
    If my memory regarding 'BigO' notation serves me correctly, these two pieces of code are _definitely_ not the same. In fact, the first code snippet will result in 100 extra assignment operations!

    Furthermore, they do not even produce the same result, so it is pretty difficult to compare them. However, the second one is comparatively much faster.

    However, given today's hardware speeds, the difference would be so insignificant that it would be irrelevant.

    my $0.02,

    /wj

Similar Threads

  1. Hardware (un)support for performance counter.
    By peenie in forum Computer Hardware
    Replies: 0
    Last Post: October 28th, 2003, 12:48 PM
  2. How to improve performance of SQL Server in a Very Large DataBase
    By miguelbartolo in forum Database Management
    Replies: 1
    Last Post: March 27th, 2003, 03:09 AM
  3. Replies: 1
    Last Post: February 15th, 2002, 09:46 AM
  4. int performance
    By wifpwcs in forum MySQL Help
    Replies: 1
    Last Post: February 8th, 2002, 01:13 PM
  5. performance problems because of long includes
    By Thomas Sauer in forum PHP Development
    Replies: 1
    Last Post: May 10th, 2001, 06:18 AM

IMN logo majestic logo threadwatch logo seochat tools logo