Xhgui_Profile::compare PHP Method

compare() public method

Compare this run to another run.
public compare ( Xhgui_Profile $head ) : array
$head Xhgui_Profile The other run to compare with
return array An array of comparison data.
    public function compare(Xhgui_Profile $head)
    {
        $this->calculateSelf();
        $head->calculateSelf();
        $keys = array_merge($this->_keys, $this->_exclusiveKeys);
        $emptyData = array_fill_keys($keys, 0);
        $diffPercent = array();
        $diff = array();
        foreach ($this->_collapsed as $key => $baseData) {
            $headData = $head->get($key);
            if (!$headData) {
                $diff[$key] = $this->_diffKeys($emptyData, $baseData);
                continue;
            }
            $diff[$key] = $this->_diffKeys($headData, $baseData);
            if ($key === 'main()') {
                $diffPercent[$key] = $this->_diffPercentKeys($headData, $baseData);
            }
        }
        $diff['functionCount'] = $head->getFunctionCount() - $this->getFunctionCount();
        $diffPercent['functionCount'] = $head->getFunctionCount() / $this->getFunctionCount();
        return array('base' => $this, 'head' => $head, 'diff' => $diff, 'diffPercent' => $diffPercent);
    }

Usage Example

Example #1
0
 public function testCompareWithDifferences()
 {
     $fixture = $this->_fixture[0];
     $base = new Xhgui_Profile($this->_fixture[3]);
     $head = new Xhgui_Profile($this->_fixture[4]);
     $result = $base->compare($head);
     $this->assertEquals(0, $result['diff']['main()']['ct']);
     $this->assertEquals(9861, $result['diff']['main()']['wt']);
     $this->assertEquals(-10, $result['diff']['strpos()']['wt'], 'Missing functions should show as negative');
     $this->assertEquals(-10, $result['diff']['strpos()']['ewt'], 'Should include exclusives');
     $this->assertEquals(0.5, $result['diffPercent']['functionCount']);
 }