<commit_before><?php

// emulates inserting a dir called HTMLPurifier into your class dir
set_include_path(get_include_path() . PATH_SEPARATOR . '../library/');

@include_once '../test-settings.php';

require_once 'HTMLPurifier/ConfigSchema.php';
require_once 'HTMLPurifier/Config.php';

$LEXERS = array();
$RUNS = isset($GLOBALS['HTMLPurifierTest']['Runs'])
    ? $GLOBALS['HTMLPurifierTest']['Runs'] : 2; 

require_once 'HTMLPurifier/Lexer/DirectLex.php';
$LEXERS['DirectLex'] = new HTMLPurifier_Lexer_DirectLex();

if (!empty($GLOBALS['HTMLPurifierTest']['PEAR'])) {
    require_once 'HTMLPurifier/Lexer/PEARSax3.php';
    $LEXERS['PEARSax3'] = new HTMLPurifier_Lexer_PEARSax3();
} else {
    exit('PEAR required to perform benchmark.');
}

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 RowTimer extends Benchmark_Timer
{
    
    var $name;
    
    function RowTimer($name, $auto = false) {
        $this->name = htmlentities($name);
        $this->Benchmark_Timer($auto);
    }
    
    function getOutput() {

        $total  = $this->TimeElapsed();
        $result = $this->getProfiling();
        $dashes = '';
        
        $out = '<tr>';
        
        $out .= "<td>{$this->name}</td>";
        
        $standard = false;
        
        foreach ($result as $k => $v) {
            if ($v['name'] == 'Start' || $v['name'] == 'Stop') continue;
            
            //$perc = (($v['diff'] * 100) / $total);
            //$tperc = (($v['total'] * 100) / $total);
            
            //$out .= '<td align="right">' . $v['diff'] . '</td>';
            
            if ($standard == false) $standard = $v['diff'];
            
            $perc = $v['diff'] * 100 / $standard;
            
            $out .= '<td align="right">' . number_format($perc, 2, '.', '') .
                   '%</td><td>'.number_format($v['diff'],4,'.','').'</td>';
            
        }
        
        $out .= '</tr>';
        
        return $out;
    }
}

function print_lexers() {
    global $LEXERS;
    $first = true;
    foreach ($LEXERS as $key => $value) {<commit_msg>[1.1.1] Grey outputs that are negative.<commit_after><?php

// emulates inserting a dir called HTMLPurifier into your class dir
set_include_path(get_include_path() . PATH_SEPARATOR . '../library/');

@include_once '../test-settings.php';

require_once 'HTMLPurifier/ConfigSchema.php';
require_once 'HTMLPurifier/Config.php';

$LEXERS = array();
$RUNS = isset($GLOBALS['HTMLPurifierTest']['Runs'])
    ? $GLOBALS['HTMLPurifierTest']['Runs'] : 2; 

require_once 'HTMLPurifier/Lexer/DirectLex.php';
$LEXERS['DirectLex'] = new HTMLPurifier_Lexer_DirectLex();

if (!empty($GLOBALS['HTMLPurifierTest']['PEAR'])) {
    require_once 'HTMLPurifier/Lexer/PEARSax3.php';
    $LEXERS['PEARSax3'] = new HTMLPurifier_Lexer_PEARSax3();
} else {
    exit('PEAR required to perform benchmark.');
}

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 RowTimer extends Benchmark_Timer
{
    
    var $name;
    
    function RowTimer($name, $auto = false) {
        $this->name = htmlentities($name);
        $this->Benchmark_Timer($auto);
    }
    
    function getOutput() {

        $total  = $this->TimeElapsed();
        $result = $this->getProfiling();
        $dashes = '';
        
        $out = '<tr>';
        
        $out .= "<td>{$this->name}</td>";
        
        $standard = false;
        
        foreach ($result as $k => $v) {
            if ($v['name'] == 'Start' || $v['name'] == 'Stop') continue;
            
            //$perc = (($v['diff'] * 100) / $total);
            //$tperc = (($v['total'] * 100) / $total);
            
            //$out .= '<td align="right">' . $v['diff'] . '</td>';
            
            if ($standard == false) $standard = $v['diff'];
            
            $perc = $v['diff'] * 100 / $standard;
            $bad_run = ($v['diff'] < 0);
            
            $out .= '<td align="right"'.
                   ($bad_run ? ' style="color:#AAA;"' : '').
                   '>' . number_format($perc, 2, '.', '') .
                   '%</td><td>'.number_format($v['diff'],4,'.','').'</td>';
            
        }
        
        $out .= '</tr>';
        
        return $out;
    }
}

function print_lexers() {
    global $LEXERS;
    $first = true;
    foreach ($LEXERS as $key => $value) {
{'fraction_non_alphanumeric': 0.18933333333333333, 'fraction_numerical': 0.0073846153846153844, 'mean_word_length': 2.3057627118644066, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6018569', 'n_tokens_mistral': 1686, 'n_tokens_neox': 1585, 'n_words': 312}