0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-12-22 08:21:52 +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/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
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 TinyTimer extends Benchmark_Timer
class RowTimer extends Benchmark_Timer
{
var $name;
function TinyTimer($name, $auto = false) {
function RowTimer($name, $auto = false) {
$this->name = htmlentities($name);
$this->Benchmark_Timer($auto);
}
@ -37,10 +47,10 @@ class TinyTimer extends Benchmark_Timer
//$perc = (($v['diff'] * 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, '.', '') .
// "%</td>";
// '%</td>';
}
@ -50,34 +60,48 @@ class TinyTimer extends Benchmark_Timer
}
}
?>
<html>
<head>
<title>Benchmark: DirectLex versus PEAR's XML_HTMLSax3</title>
</head>
<body>
<h1>Benchmark: DirectLex versus PEAR's XML_HTMLSax3</h1>
<table border="1">
<tr><th>Case</th><th>DirectLex</th><th>XML_HTMLSax3</th></tr>
<?php
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) {
$timer = new TinyTimer($name);
global $LEXERS;
$timer = new RowTimer($name);
$timer->start();
$lexer = new HTMLPurifier_Lexer_DirectLex();
$tokens = $lexer->tokenizeHTML($document);
$timer->setMarker('HTMLPurifier_Lexer');
$lexer = new HTMLPurifier_Lexer_PEARSax3();
$sax_tokens = $lexer->tokenizeHTML($document);
$timer->setMarker('HTMLPurifier_Lexer_Sax');
foreach($LEXERS as $key => $lexer) {
$tokens = $lexer->tokenizeHTML($document);
$timer->setMarker($key);
}
$timer->stop();
$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
$dir = 'samples/Lexer';
@ -90,7 +114,7 @@ while (false !== ($filename = readdir($dh))) {
}
// crashers
// crashers, caused infinite loops before
$snippets = array();
$snippets[] = '<a href="foo>';
@ -111,8 +135,8 @@ do_benchmark('Random input', $random);
<?php
echo '<div>Random input was: ' .
'<span colspan="4" style="font-family:monospace;">' . htmlentities($random) .
'</span></div>';
'<span colspan="4" style="font-family:monospace;">' .
htmlspecialchars($random) . '</span></div>';
?>