PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/wwwroot/mediawiki/extensions/LocalisationUpdate/tests/tokenTest.php

https://github.com/spring/spring-website
PHP | 100 lines | 34 code | 9 blank | 57 comment | 2 complexity | 5a5ddeb71dceb4b38cee53e3f080dd42 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, LGPL-3.0, BSD-3-Clause
  1. <?php
  2. $IP = strval( getenv( 'MW_INSTALL_PATH' ) ) !== ''
  3. ? getenv( 'MW_INSTALL_PATH' )
  4. : realpath( dirname( __FILE__ ) . "/../../../" );
  5. require_once "$IP/maintenance/commandLine.inc";
  6. function evalExtractArray( $php, $varname ) {
  7. eval( $php );
  8. wfSuppressWarnings();
  9. return $$varname;
  10. wfRestoreWarnings();
  11. }
  12. function confExtractArray( $php, $varname ) {
  13. try {
  14. $ce = new ConfEditor( "<?php $php" );
  15. $vars = $ce->getVars();
  16. wfSuppressWarnings();
  17. $retval = $vars[$varname];
  18. wfRestoreWarnings();
  19. } catch ( Exception $e ) {
  20. print $e . "\n";
  21. $retval = null;
  22. }
  23. return $retval;
  24. }
  25. function quickTokenExtractArray( $php, $varname ) {
  26. $reader = new QuickArrayReader( "<?php $php" );
  27. return $reader->getVar( $varname );
  28. }
  29. if ( count( $args ) ) {
  30. $sources = $args;
  31. } else {
  32. $sources =
  33. array_merge(
  34. glob( "$IP/extensions/*/*.i18n.php" ),
  35. glob( "$IP/languages/messages/Messages*.php" ) );
  36. }
  37. foreach ( $sources as $sourceFile ) {
  38. $rel = basename( $sourceFile );
  39. $out = str_replace( '/', '-', $rel );
  40. $sourceData = file_get_contents( $sourceFile );
  41. if ( preg_match( '!extensions/!', $sourceFile ) ) {
  42. $sourceData = LocalisationUpdate::cleanupExtensionFile( $sourceData );
  43. $items = 'langs';
  44. } else {
  45. $sourceData = LocalisationUpdate::cleanupFile( $sourceData );
  46. $items = 'messages';
  47. }
  48. file_put_contents( "$out.txt", $sourceData );
  49. $start = microtime( true );
  50. $eval = evalExtractArray( $sourceData, 'messages' );
  51. $deltaEval = microtime( true ) - $start;
  52. $start = microtime( true );
  53. $quick = quickTokenExtractArray( $sourceData, 'messages' );
  54. $deltaQuick = microtime( true ) - $start;
  55. $start = microtime( true );
  56. $token = confExtractArray( $sourceData, 'messages' );
  57. $deltaToken = microtime( true ) - $start;
  58. $hashEval = md5( serialize( $eval ) );
  59. $hashToken = md5( serialize( $token ) );
  60. $hashQuick = md5( serialize( $quick ) );
  61. $countEval = count( (array)$eval );
  62. $countToken = count( (array)$token );
  63. $countQuick = count( (array)$quick );
  64. printf( "%s %s %d $items - %0.1fms - eval\n",
  65. $rel, $hashEval, $countEval, $deltaEval * 1000 );
  66. printf( "%s %s %d $items - %0.1fms - QuickArrayReader\n",
  67. $rel, $hashQuick, $countQuick, $deltaQuick * 1000 );
  68. printf( "%s %s %d $items - %0.1fms - ConfEditor\n",
  69. $rel, $hashToken, $countToken, $deltaToken * 1000 );
  70. if ( $hashEval !== $hashToken || $hashEval !== $hashQuick ) {
  71. echo "FAILED on $rel\n";
  72. file_put_contents( "$out-eval.txt", var_export( $eval, true ) );
  73. file_put_contents( "$out-token.txt", var_export( $token, true ) );
  74. file_put_contents( "$out-quick.txt", var_export( $quick, true ) );
  75. #die("check eval.txt and token.txt\n");
  76. }
  77. echo "\n";
  78. }
  79. echo "ok\n";