diff --git a/benchmarks/Lexer.php b/benchmarks/Lexer.php
index 8ce9e1ac..a11f8909 100644
--- a/benchmarks/Lexer.php
+++ b/benchmarks/Lexer.php
@@ -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 .= '
' . $v['diff'] . " | ";
+ $out .= '' . $v['diff'] . ' | ';
//$out .= '' . number_format($perc, 2, '.', '') .
- // "% | ";
+ // '%';
}
@@ -50,34 +60,48 @@ class TinyTimer extends Benchmark_Timer
}
}
-?>
-
-
-Benchmark: DirectLex versus PEAR's XML_HTMLSax3
-
-
-Benchmark: DirectLex versus PEAR's XML_HTMLSax3
-
-Case | DirectLex | XML_HTMLSax3 |
- $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();
}
+?>
+
+
+Benchmark:
+
+
+Benchmark:
+
+Case | $value) {
+ echo '' . htmlspecialchars($key) . ' | ';
+}
+?>
+';
@@ -111,8 +135,8 @@ do_benchmark('Random input', $random);
Random input was: ' .
- '' . htmlentities($random) .
- '';
+ '' .
+ htmlspecialchars($random) . '';
?>