0

私は zend 部分ヘルパーを拡張して、自分のニーズに合わせて少し速くしようとしています。私がそれを行う方法のコードは、現時点では重要ではありません。

奇妙な動作をする単体テストを作成しましたが、その理由がわかりません

これはコードです:

    $garpTimeStart = microtime(true);
    for ($i = 0; $i < 999; $i++) {
        $this->_createOneGarpView();
    }
    $garpTimeTotal = microtime(true) - $garpTimeStart;

    $zendTimeStart = microtime(true);
    for ($i = 0; $i < 999; $i++) {
        $this->_createOneZendView();
    }
    $zendTimeTotal = microtime(true) - $zendTimeStart;

    $deltaPerformance = $zendTimeTotal - $garpTimeTotal;
    $this->assertTrue($deltaPerformance > 0);

基本的に、1000 個の zendView オブジェクトと 1000 個の独自の garpView オブジェクトを作成し、それぞれの作成時間を追跡します。

ここにトリッキーな部分があります:

zend ビューと garp ビューの作成順序を入れ替えただけでは、テストは失敗します。つまり、どちらを先に作成しても、より速く作成されます。(それでも、両者のパフォーマンスには明らかな違いがあります)

したがって、これは5回のうち約4回で失敗します

    $zendTimeStart = microtime(true);
    for ($i = 0; $i < 999; $i++) {
        $this->_createOneZendView();
    }
    $zendTimeTotal = microtime(true) - $zendTimeStart;

    $garpTimeStart = microtime(true);
    for ($i = 0; $i < 999; $i++) {
        $this->_createOneGarpView();
    }
    $garpTimeTotal = microtime(true) - $garpTimeStart;

    $deltaPerformance = $zendTimeTotal - $garpTimeTotal;
    $this->assertTrue($deltaPerformance > 0);

私は何が欠けていますか?これをテストするためのより適切な環境を作成するにはどうすればよいですか?

4

0 に答える 0