MediaWiki  1.23.15
UtfNormalBench.php
Go to the documentation of this file.
1 <?php
27 if( PHP_SAPI != 'cli' ) {
28  die( "Run me from the command line please.\n" );
29 }
30 
31 if( isset( $_SERVER['argv'] ) && in_array( '--icu', $_SERVER['argv'] ) ) {
32  dl( 'php_utfnormal.so' );
33 }
34 
35 require_once 'UtfNormalDefines.php';
36 require_once 'UtfNormalUtil.php';
37 require_once 'UtfNormal.php';
38 
39 define( 'BENCH_CYCLES', 5 );
40 
42  'testdata/washington.txt' => 'English text',
43  'testdata/berlin.txt' => 'German text',
44  'testdata/bulgakov.txt' => 'Russian text',
45  'testdata/tokyo.txt' => 'Japanese text',
46  'testdata/young.txt' => 'Korean text'
47 );
50 foreach( $testfiles as $file => $desc ) {
51  benchmarkTest( $normalizer, $file, $desc );
52 }
53 
54 # -------
55 
56 function benchmarkTest( &$u, $filename, $desc ) {
57  print "Testing $filename ($desc)...\n";
58  $data = file_get_contents( $filename );
59  $forms = array(
60 # 'placebo',
61  'cleanUp',
62  'toNFC',
63 # 'toNFKC',
64 # 'toNFD', 'toNFKD',
65  'NFC',
66 # 'NFKC',
67 # 'NFD', 'NFKD',
68  array( 'fastDecompose', 'fastCombiningSort', 'fastCompose' ),
69 # 'quickIsNFC', 'quickIsNFCVerify',
70  );
71  foreach( $forms as $form ) {
72  if( is_array( $form ) ) {
73  $str = $data;
74  foreach( $form as $step ) {
75  $str = benchmarkForm( $u, $str, $step );
76  }
77  } else {
78  benchmarkForm( $u, $data, $form );
79  }
80  }
81 }
82 
83 function benchTime() {
84  $st = explode( ' ', microtime() );
85  return (float)$st[0] + (float)$st[1];
86 }
87 
88 function benchmarkForm( &$u, &$data, $form ) {
89  #$start = benchTime();
90  for( $i = 0; $i < BENCH_CYCLES; $i++ ) {
91  $start = benchTime();
92  $out = $u->$form( $data, UtfNormal::$utfCanonicalDecomp );
93  $deltas[] = (benchTime() - $start);
94  }
95  #$delta = (benchTime() - $start) / BENCH_CYCLES;
96  sort( $deltas );
97  $delta = $deltas[0]; # Take shortest time
98 
99  $rate = intval( strlen( $data ) / $delta );
100  $same = (0 == strcmp( $data, $out ) );
101 
102  printf( " %20s %6.1fms %12s bytes/s (%s)\n",
103  $form,
104  $delta*1000.0,
105  number_format( $rate ),
106  ($same ? 'no change' : 'changed' ) );
107  return $out;
108 }
$normalizer
$normalizer
Definition: UtfNormalBench.php:48
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
benchmarkForm
benchmarkForm(&$u, &$data, $form)
Definition: UtfNormalBench.php:88
$form
usually copyright or history_copyright This message must be in HTML not wikitext $subpages will be ignored and the rest of subPageSubtitle() will run. 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink' whether MediaWiki currently thinks this is a CSS JS page Hooks may change this value to override the return value of Title::isCssOrJsPage(). 'TitleIsAlwaysKnown' whether MediaWiki currently thinks this page is known isMovable() always returns false. $title whether MediaWiki currently thinks this page is movable Hooks may change this value to override the return value of Title::isMovable(). 'TitleIsWikitextPage' whether MediaWiki currently thinks this is a wikitext page Hooks may change this value to override the return value of Title::isWikitextPage() 'TitleMove' use UploadVerification and UploadVerifyFile instead $form
Definition: hooks.txt:2584
UtfNormal\$utfCanonicalDecomp
static $utfCanonicalDecomp
Definition: UtfNormal.php:62
$testfiles
$testfiles
Definition: UtfNormalBench.php:41
benchmarkTest
foreach( $testfiles as $file=> $desc) benchmarkTest(&$u, $filename, $desc)
Definition: UtfNormalBench.php:56
$out
$out
Definition: UtfNormalGenerate.php:167
UtfNormal
Unicode normalization routines for working with UTF-8 strings.
Definition: UtfNormal.php:48
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
benchTime
benchTime()
Definition: UtfNormalBench.php:83
$file
if(PHP_SAPI !='cli') $file
Definition: UtfNormalTest2.php:30
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
UtfNormal\loadData
static loadData()
Load the basic composition data if necessary.
Definition: UtfNormal.php:191
BENCH_CYCLES
const BENCH_CYCLES
Definition: UtfNormalBench.php:39