Okay, folks... my semi, sorta, kinda, somewhat, slightly scientific analysis has been done, yet again.
The Objective: try and determine what's the fastest method to generate dynamic strings.
Method: Compare 7 different methods of string construction:
1: printf();
2: print (using double-quoted strings and string concatenation);
3: print (using single-quoted strings and string concatenation);
4: echo (using single-quoted strings and dot concatenation);
5: echo (using single-quoted strings and comma concatenation);
6: echo (using double-quoted strings and dot concatenation);
7: echo (using double-quoted strings and comma concatenation);
Environment: SuSE 7.3 Linux on a 550 MHz PIII w/ 256MB of RAM; Apache 1.3.20 httpd server, PHP 4.0.6 installed as a DSO, Zend Engine v 1.0.6.
All tests consisted of 20000 iterations of a loop, where inside the loop, the following line was printed: 'His name is: Jake Mahoney [iteration number].' Each test was done independently of each other test, and each test was run forty times.
RESULTS:
Method #1 - printf("His name is : %s %s %d.",$fname, $lname, $i);
MIN: 2.4771 s
AVG: 2.7258 s
MAX: 3.9391 s
Methos #2 - print("His name is: " . $fname . " " . $lname . " " . $i . ".");
MIN: 2.5175 s
AVG: 2.7607 s
MAX: 3.5014 s
Method #3 - print('His name is: ' . $fname . ' ' . $lname . ' ' . $i . '.');
MIN: 2.4986 s
AVG: 2.7402 s
MAX: 3.4416 s
Method #4 - echo 'His name is: ' . $fname . ' ' . $lname . ' ' . $i . '.';
MIN: 2.4986 s
AVG: 2.7402 s
MAX: 3.4416 s
Method #5 - echo 'His name is: ' , $fname , ' ' , $lname, ' ', $i , '.';
MIN: 2.4650 s
AVG: 2.7446 s
MAX: 4.3656 s
Method #6 - echo "His name is: " . $fname . " " . $lname . " " . $i . ".";
MIN: 2.4838 s
AVG: 2.6925 s
MAX: 3.0803 s
Method #7 - echo "His name is: " , $fname, " ", $lname, " ", $i, ".";
MIN: 2.4875 s
AVG: 2.6858 s
MAX: 3.3571 s
Conclusions:
1 - I really need to get high. Soon!
2 - The Mets probably won't take the NL East pennant this year.
3 - Steve Howe is an incredible guitarist.