MediaWiki  master
bench_utf8_title_check.php
Go to the documentation of this file.
00001 <?php
00024 require_once( __DIR__ . '/Benchmarker.php' );
00025 
00032 class bench_utf8_title_check extends Benchmarker {
00033 
00034         private $canRun;
00035 
00036         private $data;
00037 
00038         public function __construct() {
00039                 parent::__construct();
00040 
00041                 $this->data = array (
00042                         "",
00043                         "United States of America", // 7bit ASCII
00044                         "S%C3%A9rie%20t%C3%A9l%C3%A9vis%C3%A9e",
00045                         "Acteur%7CAlbert%20Robbins%7CAnglais%7CAnn%20Donahue%7CAnthony%20E.%20Zuiker%7CCarol%20Mendelsohn",
00046                         // This comes from bug 36839
00047                         "Acteur%7CAlbert%20Robbins%7CAnglais%7CAnn%20Donahue%7CAnthony%20E.%20Zuiker%7CCarol%20Mendelsohn%7C"
00048                         . "Catherine%20Willows%7CDavid%20Hodges%7CDavid%20Phillips%7CGil%20Grissom%7CGreg%20Sanders%7CHodges%7C"
00049                         . "Internet%20Movie%20Database%7CJim%20Brass%7CLady%20Heather%7C"
00050                         . "Les%20Experts%20(s%C3%A9rie%20t%C3%A9l%C3%A9vis%C3%A9e)%7CLes%20Experts%20:%20Manhattan%7C"
00051                         . "Les%20Experts%20:%20Miami%7CListe%20des%20personnages%20des%20Experts%7C"
00052                         . "Liste%20des%20%C3%A9pisodes%20des%20Experts%7CMod%C3%A8le%20discussion:Palette%20Les%20Experts%7C"
00053                         . "Nick%20Stokes%7CPersonnage%20de%20fiction%7CPersonnage%20fictif%7CPersonnage%20de%20fiction%7C"
00054                         . "Personnages%20r%C3%A9currents%20dans%20Les%20Experts%7CRaymond%20Langston%7CRiley%20Adams%7C"
00055                         . "Saison%201%20des%20Experts%7CSaison%2010%20des%20Experts%7CSaison%2011%20des%20Experts%7C"
00056                         . "Saison%2012%20des%20Experts%7CSaison%202%20des%20Experts%7CSaison%203%20des%20Experts%7C"
00057                         . "Saison%204%20des%20Experts%7CSaison%205%20des%20Experts%7CSaison%206%20des%20Experts%7C"
00058                         . "Saison%207%20des%20Experts%7CSaison%208%20des%20Experts%7CSaison%209%20des%20Experts%7C"
00059                         . "Sara%20Sidle%7CSofia%20Curtis%7CS%C3%A9rie%20t%C3%A9l%C3%A9vis%C3%A9e%7CWallace%20Langham%7C"
00060                         . "Warrick%20Brown%7CWendy%20Simms%7C%C3%89tats-Unis"
00061                 );
00062 
00063                 $this->canRun = function_exists ( 'mb_check_encoding' );
00064 
00065                 if ( $this->canRun ) {
00066                         $this->mDescription = "Benchmark for using a regexp vs. mb_check_encoding to check for UTF-8 encoding.";
00067                         mb_internal_encoding( 'UTF-8' );
00068                 } else {
00069                         $this->mDescription = "CANNOT RUN benchmark using mb_check_encoding: function not available.";
00070                 }
00071         }
00072 
00073         public function execute() {
00074                 if ( !$this->canRun ) {
00075                         return;
00076                 }
00077                 $benchmarks = array();
00078                 foreach ($this->data as $val) {
00079                         $benchmarks[] = array(
00080                                 'function' => array( $this, 'use_regexp' ),
00081                                 'args' => array( rawurldecode ( $val ) )
00082                         );
00083                         $benchmarks[] = array(
00084                                 'function' => array( $this, 'use_regexp_non_capturing' ),
00085                                 'args' => array( rawurldecode ( $val ) )
00086                         );
00087                         $benchmarks[] = array(
00088                                 'function' => array( $this, 'use_regexp_once_only' ),
00089                                 'args' => array( rawurldecode ( $val ) )
00090                         );
00091                         $benchmarks[] = array(
00092                                 'function' => array( $this, 'use_mb_check_encoding' ),
00093                                 'args' => array( rawurldecode ( $val ) )
00094                         );
00095                 }
00096                 $this->bench( $benchmarks );
00097                 print $this->getFormattedResults();
00098         }
00099 
00100         private $isutf8;
00101 
00102         function use_regexp( $s ) {
00103                 $this->isutf8 = preg_match( '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
00104                                 '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s );
00105         }
00106 
00107         function use_regexp_non_capturing( $s ) {
00108                 // Same as above with a non-capturing subgroup.
00109                 $this->isutf8 = preg_match( '/^(?:[\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
00110                                 '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s );
00111         }
00112 
00113         function use_regexp_once_only( $s ) {
00114                 // Same as above with a once-only subgroup.
00115                 $this->isutf8 = preg_match( '/^(?>[\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
00116                                 '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s );
00117         }
00118 
00119         function use_mb_check_encoding( $s ) {
00120                 $this->isutf8 = mb_check_encoding( $s, 'UTF-8' );
00121         }
00122 
00123 }
00124 
00125 $maintClass = 'bench_utf8_title_check';
00126 require_once( RUN_MAINTENANCE_IF_MAIN );