Index: trunk/extensions/Translate/scripts/yaml-tests.php |
— | — | @@ -0,0 +1,94 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Script for comparing supported YAML parser implementations |
| 5 | + * |
| 6 | + * @author Niklas Laxstrom |
| 7 | + * |
| 8 | + * @copyright Copyright © 2010, Niklas Laxström |
| 9 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 10 | + * @file |
| 11 | + */ |
| 12 | + |
| 13 | +// Standard boilerplate to define $IP |
| 14 | +if ( getenv( 'MW_INSTALL_PATH' ) !== false ) { |
| 15 | + $IP = getenv( 'MW_INSTALL_PATH' ); |
| 16 | +} else { |
| 17 | + $dir = dirname( __FILE__ ); $IP = "$dir/../../.."; |
| 18 | +} |
| 19 | +require_once( "$IP/maintenance/Maintenance.php" ); |
| 20 | + |
| 21 | +class YamlTests extends Maintenance { |
| 22 | + public function __construct() { |
| 23 | + parent::__construct(); |
| 24 | + $this->mDescription = 'Script for comparing supported YAML parser implementations'; |
| 25 | + } |
| 26 | + |
| 27 | + public function execute() { |
| 28 | + global $wgTranslateGroupFiles, $wgTranslateYamlLibrary; |
| 29 | + $documents = array(); |
| 30 | + $times = array(); |
| 31 | + $mems = array(); |
| 32 | + $mempeaks = array(); |
| 33 | + |
| 34 | + foreach ( array( 'syck', 'spyc', 'syck-pecl' ) as $driver ) { |
| 35 | + $mempeaks[$driver] = -memory_get_peak_usage( true ); |
| 36 | + $mems[$driver] = -memory_get_usage( true ); |
| 37 | + $times[$driver] = -microtime( true ); |
| 38 | + $wgTranslateYamlLibrary = $driver; |
| 39 | + $documents[$driver] = array(); |
| 40 | + foreach ( $wgTranslateGroupFiles as $file ) { |
| 41 | + foreach ( self::parseGroupFile( $file ) as $id => $docu ) { |
| 42 | + $documents[$driver]["$file-$id"] = $docu; |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + $times[$driver] += microtime( true ); |
| 47 | + $mems[$driver] += memory_get_usage( true ); |
| 48 | + $mempeaks[$driver] += memory_get_peak_usage( true ); |
| 49 | + |
| 50 | + self::sortNestedArrayAssoc( $documents[$driver] ); |
| 51 | + file_put_contents( "yaml-test-$driver.txt", var_export( $documents[$driver], true ) ); |
| 52 | + } |
| 53 | + var_dump( $times ); |
| 54 | + var_dump( $mems ); |
| 55 | + var_dump( $mempeaks ); |
| 56 | + } |
| 57 | + |
| 58 | + public static function parseGroupFile( $filename ) { |
| 59 | + $data = file_get_contents( $filename ); |
| 60 | + $documents = preg_split( "/^---$/m", $data, -1, PREG_SPLIT_NO_EMPTY ); |
| 61 | + $groups = array(); |
| 62 | + $template = false; |
| 63 | + foreach ( $documents as $document ) { |
| 64 | + $document = TranslateYaml::loadString( $document ); |
| 65 | + if ( isset( $document['TEMPLATE'] ) ) { |
| 66 | + $template = $document['TEMPLATE']; |
| 67 | + } else { |
| 68 | + if ( !isset( $document['BASIC']['id'] ) ) { |
| 69 | + trigger_error( "No path ./BASIC/id (group id not defined) in yaml document located in $filename" ); |
| 70 | + continue; |
| 71 | + } |
| 72 | + $groups[$document['BASIC']['id']] = $document; |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + foreach ( $groups as $i => $group ) { |
| 77 | + $groups[$i] = TranslateYaml::mergeTemplate( $template, $group ); |
| 78 | + } |
| 79 | + |
| 80 | + return $groups; |
| 81 | + } |
| 82 | + |
| 83 | + public static function sortNestedArrayAssoc(&$a) { |
| 84 | + ksort($a); |
| 85 | + foreach ($a as $key => &$value) { |
| 86 | + if (is_array($value)) { |
| 87 | + self::sortNestedArrayAssoc($value); |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | +} |
| 93 | + |
| 94 | +$maintClass = 'YamlTests'; |
| 95 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
Property changes on: trunk/extensions/Translate/scripts/yaml-tests.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 96 | + native |