InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search
  • Home
  • > Tutorials
  • > PHP cookbook

PHP echo – comma (,) vs dot (.) performance benchmarks

By admin on Dec 17, 2015

PHP echo allow comma (,) for concatenating various values in addition to dot (.). This works only for echo though. It is sometimes discussed comma may perform better than dot. We will use a php benchmark code to see if there is any significant performance difference.

php-echo-dot-vs-comma-syntax

echo – comma (,) vs dot (.) benchmark environment

  1. OS: Ubuntu 14.04.2 LTS Linux
  2. Machine: Amazon t2.mciro

Benchmark code

Here is the code we’ll use for these benchmarks:

?php
$len = $argv[1];
$loop = $argv[2];
for ($i=0; $i < $len; $i++) {
  $str1 .= "a";
  $str2 .= "b";
  $str3 .= "c";
  $str4 .= "d";
  $str5 .= "e";
}

$t1 = microtime(true);
for ($i=0; $i < $loop; $i++) {
  ob_start();
  echo $str1 . $str2 . $str3 . $str4 . $str5 . "\n";
  ob_end_clean();
}
$t2 = microtime(true);
$diff1 = $t2 - $t1;

for ($i=0; $i < $loop; $i++) {
  ob_start();
  echo $str1 , $str2 , $str3 , $str4, $str5, "\n";
  ob_end_clean();
}
$t3 = microtime(true);
$diff2 = $t3 - $t2;

echo "diff1=$diff1 diff2=$diff2\n";
?>

Benchmark results

Time (s) with dot (.) Time(s) with comma (,)
10 char string, 10M loop iterations 5.95 6.28
100 char string, 10M loop iterations 6.52 6.19

Conclusion

There is no significant difference between the performance of dot vs comma in echo. For smaller strings dot performed little better and for larger strings, comma performed little better. Probably one should not put effort in optimisation on this topic.

Suggested posts:

  1. Php apc vs memcache
  2. mysql – how to enable query logs
  3. Bash – newline and other escape character in string
  4. Php regex delimiter examples
  5. How to install wordpress on Amazon AWS-EC2 Classic Ubuntu Linux micro instance
  6. AngularJS format date using date filter
  7. How to create animated gif using Mac preview
  8. Curl with download/upload rate limit – code snippets
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Linux, PHP, PHP cookbook, Tutorials, Ubuntu Linux
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress