;;;;$i = 123; ;;;;echo $i, PHP_EOL;
这段代码是不是很奇葩,使用`;`作为代码缩进符号但是它是合法的语句,可以正常运行。并且在Java、PHP等语言中,都可以正常使用。
我第一次得知这种写法,是上学时候,Java课老师告诉我们的……
那么这么写除了脑残装B酷炫以外,它对性能是否有影响呢?
<?php function test1($i) { if(0 === $i % 2) { return 1; } else { return 0; } } function test2($i) { ;;;;if(0 === $i % 2) { ;;;;;;;;return 1; } else { ;;;;;;;;return 0; } } $count = 10000000; $t = microtime(true); for($i = 0; $i < $count; ++$i) { test1($i); } echo 'test1: ', microtime(true) - $t, PHP_EOL; $t = microtime(true); for($i = 0; $i < $count; ++$i) { test2($i); } echo 'test2: ', microtime(true) - $t, PHP_EOL;
通过上面的代码运行得出,使用`;`作为缩进符,会略慢于正常写法。
所以,不要追求酷炫个性,而选择这种缩进方式哦!
哈哈 如果是java的话 估计不会性能有影响,因为它有独立的编译阶段