【宇潤平常瘋測-001】使用 ; 做爲代碼縮進符號

;;;;$i = 123;
;;;;echo $i, PHP_EOL;

這段代碼是否是很奇葩,使用;做爲代碼縮進符號可是它是合法的語句,能夠正常運行。而且在Java、PHP等語言中,均可以正常使用。php

我第一次得知這種寫法,是上學時候,Java課老師告訴咱們的……性能

那麼這麼寫除了腦殘裝B酷炫之外,它對性能是否有影響呢?code

<?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;

經過上面的代碼運行得出,使用;做爲縮進符,會略慢於正常寫法。io

因此,不要追求酷炫個性,而選擇這種縮進方式哦!function

相關文章
相關標籤/搜索