Skip to content

Instantly share code, notes, and snippets.

@msonnabaum
Created February 27, 2013 23:36

Revisions

  1. msonnabaum created this gist Feb 27, 2013.
    43 changes: 43 additions & 0 deletions drupal_yaml_parsing.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    <?php

    require './core/vendor/autoload.php';
    use Symfony\Component\Yaml\Parser;

    function quantile($values, $p) {
    sort($values);
    $H = (count($values) - 1) * $p + 1;
    $h = floor($H);
    $v = $values[$h - 1];
    $e = $H - $h;
    return $e ? $v + $e * ($values[$h] - $v) : $v;
    }

    function sumarize($values) {
    $output = array();
    $output['min'] = number_format(min($values), 4);
    $output['max'] = number_format(max($values), 4);
    $output['mean'] = number_format(array_sum($values) / count($values), 4);
    $output['median'] = number_format(quantile($values, 0.5), 4);
    $output['95th'] = number_format(quantile($values, 0.95), 4);
    return $output;
    }

    $file_list = shell_exec('find core| grep -v vendor | grep \.yml$');
    $files = array_filter(explode("\n", $file_list));

    $extension_times = array();
    $symfony_times = array();

    foreach ($files as $file) {
    $start = microtime(TRUE);
    $extension = yaml_parse_file($file);
    $extension_times[] = (microtime(TRUE) - $start) * 1000;

    $parser = new Parser();
    $start = microtime(TRUE);
    $symfony = $parser->parse(file_get_contents($file));
    $symfony_times[] = (microtime(TRUE) - $start) * 1000;
    }

    print yaml_emit(array('extension' => sumarize($extension_times)));
    print yaml_emit(array('symfony' => sumarize($symfony_times)));