From d22140b9a6713cf98b0003bef5f836a4fcdf837d Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sat, 22 Jul 2006 14:28:51 +0000 Subject: [PATCH] Fix benchmarks to work in PHP4 by excluding DOMLex. git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@82 48356398-32a2-884e-a903-53898d9a118a --- benchmarks/Lexer.php | 76 +++++++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 26 deletions(-) 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

- - - $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: <?php print_lexers(); ?> + + +

Benchmark:

+
CaseDirectLexXML_HTMLSax3
+ $value) { + echo ''; +} +?> +'; @@ -111,8 +135,8 @@ do_benchmark('Random input', $random); Random input was: ' . - '' . htmlentities($random) . - ''; + '' . + htmlspecialchars($random) . ''; ?>
Case' . htmlspecialchars($key) . '