26 public function __construct() {
27 parent::__construct();
28 $this->addDescription(
'Script for comparing supported YAML parser implementations.' );
29 $this->requireExtension(
'Translate' );
32 public function execute() {
33 global $wgTranslateGroupFiles, $wgTranslateYamlLibrary;
39 foreach ( [
'spyc',
'phpyaml' ] as $driver ) {
40 $mempeaks[$driver] = -memory_get_peak_usage(
true );
41 $mems[$driver] = -memory_get_usage(
true );
42 $times[$driver] = -microtime(
true );
43 $wgTranslateYamlLibrary = $driver;
44 $documents[$driver] = [];
45 foreach ( $wgTranslateGroupFiles as $file ) {
46 foreach ( self::parseGroupFile( $file ) as $id => $docu ) {
47 $documents[$driver][
"$file-$id"] = $docu;
51 $times[$driver] += microtime(
true );
52 $mems[$driver] += memory_get_usage(
true );
53 $mempeaks[$driver] += memory_get_peak_usage(
true );
55 self::sortNestedArrayAssoc( $documents[$driver] );
56 file_put_contents(
"yaml-test-$driver.txt", var_export( $documents[$driver],
true ) );
57 file_put_contents(
"yaml-output-$driver.txt", Yaml::dump( $documents[$driver] ) );
61 var_dump( $mempeaks );
64 public static function parseGroupFile( $filename ) {
65 $data = file_get_contents( $filename );
66 $documents = preg_split(
"/^---$/m", $data, -1, PREG_SPLIT_NO_EMPTY );
69 foreach ( $documents as $document ) {
70 $document = Yaml::loadString( $document );
71 if ( isset( $document[
'TEMPLATE'] ) ) {
72 $template = $document[
'TEMPLATE'];
74 if ( !isset( $document[
'BASIC'][
'id'] ) ) {
75 trigger_error(
'No path ./BASIC/id (group id not defined) ' .
76 "in yaml document located in $filename" );
79 $groups[$document[
'BASIC'][
'id']] = $document;
83 return array_map(
static function ( array $group ) use ( $template ): array {
84 return MessageGroupConfigurationParser::mergeTemplate( $template, $group );
88 public static function sortNestedArrayAssoc( &$a ) {
90 foreach ( $a as &$value ) {
91 if ( is_array( $value ) ) {
92 self::sortNestedArrayAssoc( $value );