Esempio n. 1
0
            }
        }
        // Key not in array
        return false;
    }
}
class BenchmarkSetLookup extends AbstractBenchmark
{
    public function execute()
    {
        $randKey = rand(1000, 10000);
        return isset($this->testSet[$randKey]);
    }
}
// Create a new benchmark instance
$phpench = new mre\PHPench(new \mre\PHPench\Aggregator\MedianAggregator());
// Use GnuPlot for output
$oOutput = new \mre\PHPench\Output\GnuPlotOutput('test2.png', 1024, 768);
// Alternatively, print the values to the terminal
//$oOutput = new \mre\PHPench\Output\CliOutput();
$oOutput->setTitle('Compare set and list lookup in PHP');
$phpench->setOutput($oOutput);
// Add your test to the instance
$phpench->addBenchmark(new BenchmarkSetLookup(), 'set');
$phpench->addBenchmark(new BenchmarkListLookup(), 'list');
// Run the benchmark and plot the results in realtime.
// With the second parameter you can specify
// the start, end and step for each call
$phpench->setInput(range(1, pow(2, 16), 1024));
$phpench->setRepetitions(4);
$phpench->run();