Merge "Add support for PHP7 random_bytes in favor of mcrypt_create_iv"
[lhc/web/wiklou.git] / maintenance / benchmarks / bench_utf8_title_check.php
index b742f66..b2f7e96 100644 (file)
 require_once __DIR__ . '/Benchmarker.php';
 
 /**
- * This little benchmark executes the regexp used in Language->checkTitleEncoding()
- * and compares its execution time against that of mb_check_encoding, if available.
+ * This little benchmark executes the regexp formerly used in Language->checkTitleEncoding()
+ * and compares its execution time against that of mb_check_encoding.
  *
  * @ingroup Benchmark
  */
 class BenchUtf8TitleCheck extends Benchmarker {
-       private $canRun;
-
        private $data;
 
        public function __construct() {
                parent::__construct();
 
                // @codingStandardsIgnoreStart Ignore long line warnings.
-               $this->data = array(
+               $this->data = [
                        "",
                        "United States of America", // 7bit ASCII
                        "S%C3%A9rie%20t%C3%A9l%C3%A9vis%C3%A9e",
                        "Acteur%7CAlbert%20Robbins%7CAnglais%7CAnn%20Donahue%7CAnthony%20E.%20Zuiker%7CCarol%20Mendelsohn",
-                       // This comes from bug 36839
+                       // This comes from T38839
                        "Acteur%7CAlbert%20Robbins%7CAnglais%7CAnn%20Donahue%7CAnthony%20E.%20Zuiker%7CCarol%20Mendelsohn%7C"
                        . "Catherine%20Willows%7CDavid%20Hodges%7CDavid%20Phillips%7CGil%20Grissom%7CGreg%20Sanders%7CHodges%7C"
                        . "Internet%20Movie%20Database%7CJim%20Brass%7CLady%20Heather%7C"
@@ -58,42 +56,32 @@ class BenchUtf8TitleCheck extends Benchmarker {
                        . "Saison%207%20des%20Experts%7CSaison%208%20des%20Experts%7CSaison%209%20des%20Experts%7C"
                        . "Sara%20Sidle%7CSofia%20Curtis%7CS%C3%A9rie%20t%C3%A9l%C3%A9vis%C3%A9e%7CWallace%20Langham%7C"
                        . "Warrick%20Brown%7CWendy%20Simms%7C%C3%89tats-Unis"
-               );
+               ];
                // @codingStandardsIgnoreEnd
 
-               $this->canRun = function_exists( 'mb_check_encoding' );
-
-               if ( $this->canRun ) {
-                       $this->mDescription = "Benchmark for using a regexp vs. mb_check_encoding " .
-                               "to check for UTF-8 encoding.";
-                       mb_internal_encoding( 'UTF-8' );
-               } else {
-                       $this->mDescription = "CANNOT RUN benchmark using mb_check_encoding: function not available.";
-               }
+               $this->addDescription( "Benchmark for using a regexp vs. mb_check_encoding " .
+                       "to check for UTF-8 encoding." );
        }
 
        public function execute() {
-               if ( !$this->canRun ) {
-                       return;
-               }
-               $benchmarks = array();
+               $benchmarks = [];
                foreach ( $this->data as $val ) {
-                       $benchmarks[] = array(
-                               'function' => array( $this, 'use_regexp' ),
-                               'args' => array( rawurldecode( $val ) )
-                       );
-                       $benchmarks[] = array(
-                               'function' => array( $this, 'use_regexp_non_capturing' ),
-                               'args' => array( rawurldecode( $val ) )
-                       );
-                       $benchmarks[] = array(
-                               'function' => array( $this, 'use_regexp_once_only' ),
-                               'args' => array( rawurldecode( $val ) )
-                       );
-                       $benchmarks[] = array(
-                               'function' => array( $this, 'use_mb_check_encoding' ),
-                               'args' => array( rawurldecode( $val ) )
-                       );
+                       $benchmarks[] = [
+                               'function' => [ $this, 'use_regexp' ],
+                               'args' => [ rawurldecode( $val ) ]
+                       ];
+                       $benchmarks[] = [
+                               'function' => [ $this, 'use_regexp_non_capturing' ],
+                               'args' => [ rawurldecode( $val ) ]
+                       ];
+                       $benchmarks[] = [
+                               'function' => [ $this, 'use_regexp_once_only' ],
+                               'args' => [ rawurldecode( $val ) ]
+                       ];
+                       $benchmarks[] = [
+                               'function' => [ $this, 'use_mb_check_encoding' ],
+                               'args' => [ rawurldecode( $val ) ]
+                       ];
                }
                $this->bench( $benchmarks );
                print $this->getFormattedResults();