0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-01-03 13:21:51 +00:00

Fix benchmarks to work in PHP4 by excluding DOMLex.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@82 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2006-07-22 14:28:51 +00:00
parent f0d74a3bf4
commit d22140b9a6

View File

@ -6,17 +6,27 @@ set_include_path(get_include_path() . PATH_SEPARATOR . '../../');
require_once 'HTMLPurifier/Lexer/DirectLex.php'; require_once 'HTMLPurifier/Lexer/DirectLex.php';
require_once 'HTMLPurifier/Lexer/PEARSax3.php'; require_once 'HTMLPurifier/Lexer/PEARSax3.php';
$LEXERS = array(
'DirectLex' => new HTMLPurifier_Lexer_DirectLex(),
'PEARSax3' => new HTMLPurifier_Lexer_PEARSax3()
);
if (version_compare(PHP_VERSION, '5', '>=')) {
require_once 'HTMLPurifier/Lexer/DOMLex.php';
$LEXERS['DOMLex'] = new HTMLPurifier_Lexer_DOMLex();
}
// PEAR // PEAR
require_once 'Benchmark/Timer.php'; // to do the timing require_once 'Benchmark/Timer.php'; // to do the timing
require_once 'Text/Password.php'; // for generating random input require_once 'Text/Password.php'; // for generating random input
// custom class to aid unit testing // custom class to aid unit testing
class TinyTimer extends Benchmark_Timer class RowTimer extends Benchmark_Timer
{ {
var $name; var $name;
function TinyTimer($name, $auto = false) { function RowTimer($name, $auto = false) {
$this->name = htmlentities($name); $this->name = htmlentities($name);
$this->Benchmark_Timer($auto); $this->Benchmark_Timer($auto);
} }
@ -37,10 +47,10 @@ class TinyTimer extends Benchmark_Timer
//$perc = (($v['diff'] * 100) / $total); //$perc = (($v['diff'] * 100) / $total);
//$tperc = (($v['total'] * 100) / $total); //$tperc = (($v['total'] * 100) / $total);
$out .= '<td align="right">' . $v['diff'] . "</td>"; $out .= '<td align="right">' . $v['diff'] . '</td>';
//$out .= '<td align="right">' . number_format($perc, 2, '.', '') . //$out .= '<td align="right">' . number_format($perc, 2, '.', '') .
// "%</td>"; // '%</td>';
} }
@ -50,34 +60,48 @@ class TinyTimer extends Benchmark_Timer
} }
} }
?> function print_lexers() {
<html> global $LEXERS;
<head> $first = true;
<title>Benchmark: DirectLex versus PEAR's XML_HTMLSax3</title> foreach ($LEXERS as $key => $value) {
</head> if (!$first) echo ' / ';
<body> echo htmlspecialchars($key);
<h1>Benchmark: DirectLex versus PEAR's XML_HTMLSax3</h1> $first = false;
<table border="1"> }
<tr><th>Case</th><th>DirectLex</th><th>XML_HTMLSax3</th></tr> }
<?php
function do_benchmark($name, $document) { function do_benchmark($name, $document) {
$timer = new TinyTimer($name); global $LEXERS;
$timer = new RowTimer($name);
$timer->start(); $timer->start();
$lexer = new HTMLPurifier_Lexer_DirectLex(); foreach($LEXERS as $key => $lexer) {
$tokens = $lexer->tokenizeHTML($document); $tokens = $lexer->tokenizeHTML($document);
$timer->setMarker('HTMLPurifier_Lexer'); $timer->setMarker($key);
}
$lexer = new HTMLPurifier_Lexer_PEARSax3();
$sax_tokens = $lexer->tokenizeHTML($document);
$timer->setMarker('HTMLPurifier_Lexer_Sax');
$timer->stop(); $timer->stop();
$timer->display(); $timer->display();
} }
?>
<html>
<head>
<title>Benchmark: <?php print_lexers(); ?></title>
</head>
<body>
<h1>Benchmark: <?php print_lexers(); ?></h1>
<table border="1">
<tr><th>Case</th><?php
foreach ($LEXERS as $key => $value) {
echo '<th>' . htmlspecialchars($key) . '</th>';
}
?></tr>
<?php
// ************************************************************************** //
// sample of html pages // sample of html pages
$dir = 'samples/Lexer'; $dir = 'samples/Lexer';
@ -90,7 +114,7 @@ while (false !== ($filename = readdir($dh))) {
} }
// crashers // crashers, caused infinite loops before
$snippets = array(); $snippets = array();
$snippets[] = '<a href="foo>'; $snippets[] = '<a href="foo>';
@ -111,8 +135,8 @@ do_benchmark('Random input', $random);
<?php <?php
echo '<div>Random input was: ' . echo '<div>Random input was: ' .
'<span colspan="4" style="font-family:monospace;">' . htmlentities($random) . '<span colspan="4" style="font-family:monospace;">' .
'</span></div>'; htmlspecialchars($random) . '</span></div>';
?> ?>