From e7f5b1674ddc85dcb8f39d90031124697ce38a06 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 16 Apr 2006 01:09:32 +0000 Subject: [PATCH] Condense benchmark output. git-svn-id: http://htmlpurifier.org/svnroot/html_purifier/trunk@30 48356398-32a2-884e-a903-53898d9a118a --- benchmarks/HTML_Lexer.php | 69 ++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 11 deletions(-) diff --git a/benchmarks/HTML_Lexer.php b/benchmarks/HTML_Lexer.php index 19a8bac3..0ea39dc9 100644 --- a/benchmarks/HTML_Lexer.php +++ b/benchmarks/HTML_Lexer.php @@ -12,6 +12,43 @@ require_once 'Text/Password.php'; require_once '../MarkupFragment.php'; require_once '../HTML_Lexer.php'; +class TinyTimer extends Benchmark_Timer +{ + + var $name; + + function TinyTimer($name, $auto = false) { + $this->name = htmlentities($name); + $this->Benchmark_Timer($auto); + } + + function getOutput() { + + $total = $this->TimeElapsed(); + $result = $this->getProfiling(); + $dashes = ''; + + $out = ''; + + $out .= "{$this->name}"; + + foreach ($result as $k => $v) { + if ($v['name'] == 'Start' || $v['name'] == 'Stop') continue; + + $perc = (($v['diff'] * 100) / $total); + $tperc = (($v['total'] * 100) / $total); + + $out .= '' . number_format($perc, 2, '.', '') . + "%"; + + } + + $out .= ''; + + return $out; + } +} + ?> @@ -19,11 +56,13 @@ require_once '../HTML_Lexer.php';

Benchmark: HTML_Lexer versus HTMLSax

+ +start(); $lexer = new HTML_Lexer(); @@ -46,8 +85,7 @@ while (false !== ($filename = readdir($dh))) { if (strpos($filename, '.html') !== strlen($filename) - 5) continue; $document = file_get_contents($dir . '/' . $filename); - echo "

File: $filename

\n"; - do_benchmark($document); + do_benchmark("File: $filename", $document); } @@ -58,15 +96,24 @@ $snippets[] = ''; foreach ($snippets as $snippet) { - echo '

' . htmlentities($snippet) . '

'; - do_benchmark($snippet); + do_benchmark($snippet, $snippet); } // random input -$document = Text_Password::create(80, 'unpronounceable', 'qwerty <>="\''); -echo "

Random input

\n"; -echo '

' . htmlentities($document) . '

'; -do_benchmark($document); +$random = Text_Password::create(80, 'unpronounceable', 'qwerty <>="\''); -?> \ No newline at end of file +do_benchmark('Random input', $random); + +?>
CaseHTML_LexerHTML_Lexer_Sax
+ +Random input was: ' . + '' . htmlentities($random) . + ''; + +?> + + + \ No newline at end of file