Skip to content

Instantly share code, notes, and snippets.

@mcuadros
Last active December 14, 2015 22:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcuadros/5160940 to your computer and use it in GitHub Desktop.
Save mcuadros/5160940 to your computer and use it in GitHub Desktop.
Benchmarking concatenation with heredoc, single-quoted and double-quoted

PHP 5.4.12 (cli) (built: Mar 8 2013 11:16:05)

Method heredoc 1000000 iterations in 1.970294 secs

$var = <<<EOT
<html><head><title>Benchmark Test Page</title></head><body bgcolor=
"$bgcolor" text="$textcolor" {$foo->bar()} link="$link"><p><font face="$fontface"
size="$fontsize"> Here is some test text for the web page.</font>
</p></body></html>
EOT;

Method double-quoted 1000000 in 1.908962 secs

$var = "<html><head><title>Benchmark Test Page</title></head><body bgcolor=
\"$bgcolor\" text=\"$textcolor\" {$foo->bar()} link=\"$link\"><p><font face=\"$fontface\"
size=\"$fontsize\"> Here is some test text for the web page.</font>
</p></body></html>";

Method single-quoted 1000000 in 2.230555 secs

$var = '<html><head><title>Benchmark Test Page</title></head><body bgcolor=
"'. $bgcolor. '" text="'. $textcolor . '" ' . $foo->bar() . ' link="' . $link . '"><p><font face="' . $fontface . '"
size="' . $fontsize .'"> Here is some test text for the web page.</font>
</p></body></html>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment