=')) {
require_once 'HTMLPurifier/Lexer/DOMLex.php';
$LEXERS['DOMLex'] = new HTMLPurifier_Lexer_DOMLex();
}
// PEAR
require_once 'Benchmark/Timer.php'; // to do the timing
require_once 'Text/Password.php'; // for generating random input
// custom class to aid unit testing
class RowTimer extends Benchmark_Timer
{
var $name;
function RowTimer($name, $auto = false) {
$this->name = htmlentities($name);
$this->Benchmark_Timer($auto);
}
function getOutput() {
$total = $this->TimeElapsed();
$result = $this->getProfiling();
$dashes = '';
$out = '
';
$out .= "{$this->name} | ";
$standard = false;
foreach ($result as $k => $v) {
if ($v['name'] == 'Start' || $v['name'] == 'Stop') continue;
//$perc = (($v['diff'] * 100) / $total);
//$tperc = (($v['total'] * 100) / $total);
//$out .= '' . $v['diff'] . ' | ';
if ($standard == false) $standard = $v['diff'];
$perc = $v['diff'] * 100 / $standard;
$bad_run = ($v['diff'] < 0);
$out .= '' . number_format($perc, 2, '.', '') .
'% | '.number_format($v['diff'],4,'.','').' | ';
}
$out .= '
';
return $out;
}
}
function print_lexers() {
global $LEXERS;
$first = true;
foreach ($LEXERS as $key => $value) {
if (!$first) echo ' / ';
echo htmlspecialchars($key);
$first = false;
}
}
function do_benchmark($name, $document) {
global $LEXERS, $RUNS;
$config = HTMLPurifier_Config::createDefault();
$context = new HTMLPurifier_Context();
$timer = new RowTimer($name);
$timer->start();
foreach($LEXERS as $key => $lexer) {
for ($i=0; $i<$RUNS; $i++) $tokens = $lexer->tokenizeHTML($document, $config, $context);
$timer->setMarker($key);
}
$timer->stop();
$timer->display();
}
?>
Benchmark:
Benchmark:
Random input was: ' .
'' .
htmlspecialchars($random) . '';
?>