Tuurlijk

Get Files In Dir

Feb 6th, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 28.07 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL & ~E_NOTICE);
  3. /*****************************************************************************
  4.  *  Copyright notice
  5.  *
  6.  *  ⓒ 2013 Michiel Roos <michiel@maxserv.nl>
  7.  *  All rights reserved
  8.  *
  9.  *  This script is part of the TYPO3 project. The TYPO3 project is free
  10.  *  software; you can redistribute it and/or modify it under the terms of the
  11.  *  GNU General Public License as published by the Free Software Foundation;
  12.  *  either version 2 of the License, or (at your option) any later version.
  13.  *
  14.  *  The GNU General Public License can be found at
  15.  *  http://www.gnu.org/copyleft/gpl.html.
  16.  *
  17.  *  This script is distributed in the hope that it will be useful, but
  18.  *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  19.  *  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  20.  *  more details.
  21.  *
  22.  *  This copyright notice MUST APPEAR in all copies of the script!
  23.  ****************************************************************************/
  24.  
  25. /*****************************************************************************
  26.  *                    Tiny TYPO3 Test Suite v 1.0.0
  27.  *                           by: Michiel Roos
  28.  *                          _______
  29.  *                         /_  __(_)___  __  __
  30.  *                          / / / / __ \/ / / /
  31.  *                         / / / / / / / /_/ /
  32.  *                        /_/ /_/_/ /_/\__, /
  33.  *                                  /____/
  34.  *                   ________  ______  ____ _____
  35.  *                  /_  __/\ \/ / __ \/ __ \__  /
  36.  *                   / /    \  / /_/ / / / //_ <
  37.  *                  / /     / / ____/ /_/ /__/ /
  38.  *                 /_/     /_/_/    \____/____/
  39.  *             ______          __     _____       _ __
  40.  *            /_  __/__  _____/ /_   / ___/__  __(_) /____
  41.  *             / / / _ \/ ___/ __/   \__ \/ / / / / __/ _ \
  42.  *            / / /  __(__  ) /_    ___/ / /_/ / / /_/  __/
  43.  *           /_/  \___/____/\__/   /____/\__,_/_/\__/\___/
  44.  *
  45.  *           https://github.com/Tuurlijk/TinyTypo3TestSuite
  46.  *
  47.  ****************************************************************************/
  48.  
  49. /*****************************************************************************
  50.  * Setup
  51.  *
  52.  * - testname: Displayed in the page title and page header
  53.  * - runs    : The default number of runs
  54.  * - skipSets: An array of setNames to skip
  55.  ****************************************************************************/
  56. $testName = 'GeneralUtility::getFilesInDir';
  57. $runs = 100;
  58. $skipSets = array();
  59.  
  60. /*****************************************************************************
  61.  * Parameter Sets
  62.  *
  63.  * Define multiple parameter sets here so you can excersise the method well.
  64.  * Each method needs a description. The other parameters must match the
  65.  * parameter names of the method.
  66.  ****************************************************************************/
  67. $parameterSets = array(
  68.     'set1' => array (
  69.         'description' => 'Regular use',
  70.         'path' => __DIR__ . '/../typo3temp/',
  71.         'extensionList' => 'js,css'
  72.     ),
  73.     'set2' => array (
  74.         'description' => 'Sort mtime, no prepend path',
  75.         'path' => __DIR__ . '/../typo3temp/',
  76.         'extensionList' => 'js,css',
  77.         'prependPath' => FALSE,
  78.         'order' => 'mtime'
  79.     ),
  80.     'set3' => array (
  81.         'description' => 'Sort mtime, prepend path',
  82.         'path' => __DIR__ . '/../typo3temp/',
  83.         'extensionList' => 'js,css',
  84.         'prependPath' => TRUE,
  85.         'order' => 'mtime'
  86.     ),
  87.     'set4' => array (
  88.         'description' => 'Sort 1, prepend path',
  89.         'path' => __DIR__ . '/../typo3temp/',
  90.         'extensionList' => 'js,css',
  91.         'prependPath' => TRUE,
  92.         'order' => 1
  93.     ),
  94.     'set5' => array (
  95.         'description' => 'Sort 1, excludePattern',
  96.         'path' => __DIR__ . '/../typo3temp/',
  97.         'extensionList' => '',
  98.         'prependPath' => FALSE,
  99.         'order' => 1,
  100.         'excludePattern' => 'rtehtmlarea'
  101.     ),
  102. );
  103.  
  104. /*****************************************************************************
  105.  * Test Methods:
  106.  *
  107.  * Define your test methods here. Name them version1 - version[n].
  108.  * version1 must be the baseline implementation.
  109.  ****************************************************************************/
  110.  
  111. $descriptions['version1'] = 'Baseline';
  112. function version1($path, $extensionList = '', $prependPath = FALSE, $order = '', $excludePattern = '', $md5Index = FALSE) {
  113.     // Initialize variables:
  114.     $filearray = array();
  115.     $sortarray = array();
  116.     $path = rtrim($path, '/');
  117.     // Find files+directories:
  118.     if (@is_dir($path)) {
  119.         $extensionList = strtolower($extensionList);
  120.         $d = dir($path);
  121.         if (is_object($d)) {
  122.             while ($entry = $d->read()) {
  123.                 if (@is_file(($path . '/' . $entry))) {
  124.                     $fI = pathinfo($entry);
  125.                     // Don't change this ever - extensions may depend on the fact that the hash is an md5 of the path! (import/export extension)
  126.                     $key = md5($path . '/' . $entry);
  127.                     if ((!strlen($extensionList) || inList($extensionList, strtolower($fI['extension']))) && (!strlen($excludePattern) || !preg_match(('/^' . $excludePattern . '$/'), $entry))) {
  128.                         $filearray[$key] = ($prependPath ? $path . '/' : '') . $entry;
  129.                         if ($order == 'mtime') {
  130.                             $sortarray[$key] = filemtime($path . '/' . $entry);
  131.                         } elseif ($order) {
  132.                             $sortarray[$key] = strtolower($entry);
  133.                         }
  134.                     }
  135.                 }
  136.             }
  137.             $d->close();
  138.         } else {
  139.             return 'error opening path: "' . $path . '"';
  140.         }
  141.     }
  142.     // Sort them:
  143.     if ($order) {
  144.         asort($sortarray);
  145.         $newArr = array();
  146.         foreach ($sortarray as $k => $v) {
  147.             $newArr[$k] = $filearray[$k];
  148.         }
  149.         $filearray = $newArr;
  150.     }
  151.     // Return result
  152.     reset($filearray);
  153.     return $filearray;
  154. }
  155.  
  156. $descriptions['version2'] = 'Optimized Baseline';
  157. function version2($path, $extensionList = '', $prependPath = FALSE, $order = '', $excludePattern = '', $md5Index = FALSE) {
  158.         $extensionList = ',' . $extensionList . ',';
  159.         $files = array();
  160.         $path = rtrim($path, '/');
  161.         $pathPrefix = $prependPath ? $path . '/' : '';
  162.         if (@is_dir($path)) {
  163.             $directory = dir($path);
  164.             if ($directory !== NULL && $directory !== FALSE) {
  165.                 while ($entry = $directory->read()) {
  166.                     if (@is_file(($path . '/' . $entry))) {
  167.                         if (
  168.                             ((string)$extensionList === ',,' ||
  169.                                 stripos($extensionList, ',' . pathinfo($entry, PATHINFO_EXTENSION) . ',') !== FALSE) &&
  170.                             ((string)$excludePattern === '' ||
  171.                                 !preg_match(('/^' . $excludePattern . '$/'), $entry))
  172.                         ) {
  173.                             if ($order === 'mtime') {
  174.                                 $files[$entry] = filemtime($path . '/' . $entry);
  175.                             } else {
  176.                                 $files[] = $entry;
  177.                             }
  178.                         }
  179.                     }
  180.                 }
  181.                 $directory->close();
  182.             } else {
  183.                 return 'error opening path: "' . $path . '"';
  184.             }
  185.         }
  186.  
  187.         switch ($order) {
  188.             case 'mtime':
  189.                 asort($files);
  190.                 foreach ($files as $key => $entry) {
  191.                     // Don't change this ever - extensions may depend on the fact that the hash is an md5 of the path! (import/export extension)
  192.                     $files[md5($path . '/' . $key)] = $pathPrefix . $key;
  193.                     unset($files[$key]);
  194.                 }
  195.                 break;
  196.             case 1:
  197.                 sort($files);
  198.             default:
  199.                 foreach ($files as $key => $entry) {
  200.                     // Don't change this ever - extensions may depend on the fact that the hash is an md5 of the path! (import/export extension)
  201.                     $files[md5($path . '/' . $entry)] = $pathPrefix . $entry;
  202.                     unset($files[$key]);
  203.                 }
  204.         }
  205.         return $files;
  206. }
  207.  
  208. $descriptions['version3'] = 'Using scandir( )';
  209. function version3($path, $extensionList = '', $prependPath = FALSE, $order = '', $excludePattern = '', $md5Index = FALSE) {
  210.         $extensionList = ',' . $extensionList . ',';
  211.         $files = array();
  212.         $path = rtrim($path, '/');
  213.         $pathPrefix = $path . '/';
  214.         $valuePathPrefix = $prependPath ? $pathPrefix : '';
  215.         if (@is_dir($path)) {
  216.             foreach (scandir($path) as $entry) {
  217.                 if (@is_file(($path . '/' . $entry))) {
  218.                     if (
  219.                         ((string)$extensionList === ',,' ||
  220.                             stripos($extensionList, ',' . pathinfo($entry, PATHINFO_EXTENSION) . ',') !== FALSE) &&
  221.                         ((string)$excludePattern === '' ||
  222.                             !preg_match(('/^' . $excludePattern . '$/'), $entry))
  223.                     ) {
  224.                         if ($order === 'mtime') {
  225.                             $files[$entry] = filemtime($path . '/' . $entry);
  226.                         } else {
  227.                             $files[] = $entry;
  228.                         }
  229.                     }
  230.                 }
  231.             }
  232.         } else {
  233.             return 'error opening path: "' . $path . '"';
  234.         }
  235.  
  236.         if ($order !== 'mtime') {
  237.             foreach ($files as $key => $entry) {
  238.                 // Don't change this ever - extensions may depend on the fact that the hash is an md5 of the path! (import/export extension)
  239.                 $files[md5($pathPrefix . $entry)] = $valuePathPrefix . $entry;
  240.                 unset($files[$key]);
  241.             }
  242.         } else {
  243.             asort($files);
  244.             foreach ($files as $key => $entry) {
  245.                 // Don't change this ever - extensions may depend on the fact that the hash is an md5 of the path! (import/export extension)
  246.                 $files[md5($pathPrefix . $key)] = $valuePathPrefix . $key;
  247.                 unset($files[$key]);
  248.             }
  249.         }
  250.         return $files;
  251. }
  252.  
  253. $descriptions['version4'] = 'scandir, DirectoryIterator';
  254. function version4($path, $extensionList = '', $prependPath = FALSE, $order = '', $excludePattern = '', $md5Index = FALSE) {
  255.         $extensionList = ',' . $extensionList . ',';
  256.         $files = array();
  257.         $path = rtrim($path, '/');
  258.         $pathPrefix = $path . '/';
  259.         $valuePathPrefix = $prependPath ? $pathPrefix : '';
  260.         if (@is_dir($path)) {
  261.             $iterator = new DirectoryIterator($path);
  262.             foreach ($iterator as $fileinfo) {
  263.                 if ($fileinfo->isFile()) {
  264.                     $fileName = $fileinfo->getFilename();
  265.                     if (
  266.                         ((string)$extensionList === ',,' ||
  267.                             stripos($extensionList, ',' . pathinfo($fileName, PATHINFO_EXTENSION) . ',') !== FALSE) &&
  268.                         ((string)$excludePattern === '' ||
  269.                             !preg_match(('/^' . $excludePattern . '$/'), $fileName))
  270.                     ) {
  271.                         if ($order === 'mtime') {
  272.                             $files[$fileName] = $fileinfo->getMTime();
  273.                         } else {
  274.                             $files[] = $fileName;
  275.                         }
  276.                     }
  277.                 }
  278.             }
  279.         } else {
  280.             return 'error opening path: "' . $path . '"';
  281.         }
  282.  
  283.         if ($order !== 'mtime') {
  284.             foreach ($files as $key => $entry) {
  285.                 // Don't change this ever - extensions may depend on the fact that the hash is an md5 of the path! (import/export extension)
  286.                 $files[md5($pathPrefix . $entry)] = $valuePathPrefix . $entry;
  287.                 unset($files[$key]);
  288.             }
  289.         } else {
  290.             asort($files);
  291.             foreach ($files as $key => $entry) {
  292.                 // Don't change this ever - extensions may depend on the fact that the hash is an md5 of the path! (import/export extension)
  293.                 $files[md5($pathPrefix . $key)] = $valuePathPrefix . $key;
  294.                 unset($files[$key]);
  295.             }
  296.         }
  297.         return $files;
  298.     }
  299.  
  300. $descriptions['version5'] = 'Glob';
  301. function version5($path, $extensionList = '', $prependPath = FALSE, $order = '', $excludePattern = '', $md5Index = FALSE) {
  302.         $extensionList = ($extensionList) ? $extensionList : '*';
  303.         $path = rtrim($path, '/');
  304.         $fileArray = array();
  305.         if (@is_dir($path)) {
  306.             // Conversion to case insensitive character groups:
  307.             // pdf,jpg,gif => [pP][dD][fF],[jJ][pP][gG],[gG][iI][fF]
  308.             $extensionList = strtolower($extensionList);
  309.             $caseInsensitiveExt = '';
  310.             foreach(str_split($extensionList) as $character) {
  311.                 if ($character !== '*' && $character !== ',') {
  312.                     $caseInsensitiveExt .= '[' . $character . strtoupper($character) . ']';
  313.                 } else {
  314.                     $caseInsensitiveExt .= $character;
  315.                 }
  316.             }
  317.  
  318.             // Fetch the entries
  319.             $entries = glob("$path/*.{" . $caseInsensitiveExt . "}", GLOB_BRACE | GLOB_NOSORT);
  320.  
  321.             // Exclude unwanted entries
  322.             if ($excludePattern) {
  323.                 $entries = array_filter(
  324.                     $entries,
  325.                     create_function('$a','return !preg_match("/^' . $excludePattern . '$/", $a);')
  326.                 );
  327.             }
  328.  
  329.             // If a file is found, add it to the fileArray with a md5 index
  330.             if ($order == 'mtime') {
  331.                 $sortArray = array();
  332.                 foreach ($entries as $entry) {
  333.                     if (@is_file($entry)) {
  334.                         // Don't change this ever - extensions may depend on the fact that
  335.                         // the hash is an md5 of the path! (import/export extension)
  336.                         $key = md5($entry);
  337.                         $sortArray[$key] = filemtime($entry);
  338.                         $fileArray[$key] = $prependPath ? $entry : basename($entry);
  339.                     }
  340.                 }
  341.                 asort($sortArray);
  342.                 $sortedFileArray = array();
  343.                 foreach (array_keys($sortArray) as $key) {
  344.                     $sortedFileArray[$key] = $fileArray[$key];
  345.                 }
  346.                 $fileArray = $sortedFileArray;
  347.             } else {
  348.                 foreach ($entries as $entry) {
  349.                     if (@is_file($entry)) {
  350.                         // Don't change this ever - extensions may depend on the fact that
  351.                         // the hash is an md5 of the path! (import/export extension)
  352.                         $fileArray[md5($entry)] = $prependPath ? $entry : basename($entry);
  353.                     }
  354.                 }
  355.                 if ($order) {
  356.                     asort($fileArray);
  357.                 }
  358.             }
  359.         }
  360.         return $fileArray;
  361.     }
  362.  
  363.  
  364. /*****************************************************************************
  365.  * Helper Methods:
  366.  *
  367.  * Add any methods that are needed by any of the test methods here.
  368.  ****************************************************************************/
  369.  
  370. function inList($list, $item) {
  371.     return strpos(',' . $list . ',', ',' . $item . ',') !== FALSE;
  372. }
  373.  
  374. /*****************************************************************************
  375.  * System (look, but don't touch ;-) . . . only touch if you must.
  376.  ****************************************************************************/
  377. $v = '1.0.0';
  378. $reverseExecutionOrder = 0;
  379. if (isset($_GET['source']) && $_GET['source']) {
  380.     show_source(__FILE__);
  381.     exit;
  382. }
  383. if (isset($_GET['runs'])) $runs = preg_replace('/[^0-9]/', '', $_GET['runs']);
  384. if (isset($_GET['reverseExecutionOrder'])) $reverseExecutionOrder = intval($_GET['reverseExecutionOrder']);
  385.  
  386. // Prepare
  387. $baselineTimes = $functionsToCall = $times = array();
  388. $allFunctions = get_defined_functions();
  389. $functions = array_filter($allFunctions['user'], create_function('$a','return strpos($a, "version") === 0;'));
  390. if ($reverseExecutionOrder) arsort($functions);
  391. foreach ($functions as $function) {
  392.     $xAxis[] = $function;
  393.     $functionsToCall[$function] = new ReflectionFunction($function);
  394. }
  395.  
  396. // Execute
  397. foreach ($parameterSets as $setName => $parameters) {
  398.     if (in_array($setName, $skipSets)) continue;
  399.     // Description is used later on, so clone the parameters
  400.     $functionParameters = $parameters;
  401.     unset($functionParameters['description']);
  402.     for ($i = 0; $i < $runs; $i++) {
  403.         foreach ($functions as $function) {
  404.             $start = microtime(TRUE);
  405.             $result = $functionsToCall[$function]->invokeArgs($functionParameters);
  406.             $time = microtime(TRUE) - $start;
  407.             if ($function === 'version1') {
  408.                 $baselineTimes[$setName] += $time * 1000;
  409.             }
  410.             if (is_array($result)) {
  411.                 $resultObjects[$setName][$function] = array_slice($result, 0, 20, TRUE);
  412.             } else {
  413.                 $resultObjects[$setName][$function] = $result;
  414.             }
  415.             $times[$setName][$function] += $time * 1000;
  416.         }
  417.     }
  418. }
  419.  
  420. function findFastestTimes($times) {
  421.     $fastestTimes = array();
  422.     foreach ($times as $setName => $timeData) {
  423.         foreach ($timeData as $functionName => $time) {
  424.             if (isset($fastestTimes[$functionName])) {
  425.                 $fastestTimes['overall'][$functionName] += $time;
  426.                 $fastestTimes[$setName][$functionName] += $time;
  427.             } else {
  428.                 $fastestTimes['overall'][$functionName] = $time;
  429.                 $fastestTimes[$setName][$functionName] = $time;
  430.             }
  431.         }
  432.     }
  433.     $fastestTimes = array_filter($fastestTimes, 'asort');
  434.     return $fastestTimes;
  435. }
  436.  
  437. function findWinner($times) {
  438.     $averagedTimes = array();
  439.     foreach ($times as $timeData) {
  440.         foreach ($timeData as $functionName => $time) {
  441.             $averagedTimes[$functionName] += $time;
  442.         }
  443.     }
  444.     asort($averagedTimes);
  445.     return $averagedTimes;
  446. }
  447.  
  448. $averagedTimes = findWinner($times);
  449. $fastestTimes = findFastestTimes($times);
  450.  
  451. /**
  452.  * Format an integer as a time value
  453.  *
  454.  * @param integer $time The value to format
  455.  *
  456.  * @return string
  457.  */
  458. function printSeconds($time) {
  459.     $prefix = '';
  460.     $suffix = 'μs';
  461.     if ($time < 0) {
  462.         $time = abs($time);
  463.         $prefix = '-';
  464.     }
  465.     if ($time === 0) {
  466.         $suffix = '';
  467.     }
  468.     if ($time >= 1000) {
  469.         $time = $time / 1000;
  470.         $suffix = 'ms';
  471.     }
  472.     if ($time >= 1000) {
  473.         $time = $time / 1000;
  474.         $suffix = ' s';
  475.     }
  476.     if ($time >= 60 && $suffix === ' s') {
  477.         $time = $time / 60;
  478.         $suffix = 'min!';
  479.     }
  480.     return $prefix . sprintf("%.2f {$suffix}", $time);
  481. }
  482.  
  483. ?>
  484. <html>
  485. <head>
  486.     <title><?php  echo $testName ?> | Tiny TYPO3 Test Suite v<?php echo $v ?></title>
  487.     <link rel="stylesheet" href="http://wiki.typo3.org/wiki/load.php?debug=false&amp;lang=en&amp;modules=mediawiki.legacy.commonPrint%2Cshared%7Cskins.typo3vector&amp;only=styles&amp;skin=typo3vector&amp;*" />
  488.     <style type="text/css">
  489.         h3 {
  490.             border-bottom: 1px solid #dedede;
  491.         }
  492.         h4 {
  493.             font-family: Share;
  494.             font-weight: normal;
  495.         }
  496.     </style>
  497.     <script src="http://code.jquery.com/jquery-2.0.3.min.js" type="text/javascript"></script>
  498.     <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js" type="text/javascript"></script>
  499.     <script src="http://code.highcharts.com/highcharts.js" type="text/javascript"></script>
  500.     <script src="http://code.highcharts.com/modules/exporting.js" type="text/javascript"></script>
  501. </head>
  502. <body>
  503. <div id="content" class="mw-body">
  504.     <h1 id="top"><?php echo $testName ?></h1>
  505.     <form action="<?php echo $_SERVER['SCRIPT_NAME'] ?>">
  506.         <label for="runs">Run the tests how many times?</label>
  507.         <input name="runs" id="runs" value="<?php echo $runs ?>"/>
  508.         <label for="runs"><a href="#help">Reverse execution order?</a></label>
  509.         <input type="checkbox" name="reverseExecutionOrder" id="reverseExecutionOrder" value="1" <?php echo ($reverseExecutionOrder) ? 'checked="checked"' : '' ?>/>
  510.         <input class="submit" type="submit" value="Go!"/>
  511.     </form>
  512.     <div class="timeAveraged" style="float: left;">
  513.         <p>Winner using averaged times over all sets: <strong><?php
  514.             $winner = array_slice($averagedTimes, 0, 1);
  515.             echo key($winner) ?></strong> <?php echo printSeconds(current($winner) / count($times)) ?>.</p>
  516.     <?php
  517.         if (count($parameterSets) > 1) {
  518.             echo '<ul>';
  519.             foreach ($averagedTimes as $function => $time) {
  520.                 echo '<li><b>' . $function . '</b>: ',
  521.                     ' ' . printSeconds($time / count($times)) . '</li>';
  522.             }
  523.             echo '</ul>';
  524.         }
  525.     ?>
  526.     </div>
  527.     <div class="timeFastest" style="margin-left: 50%;">
  528.         <p>The fastest function in any set is <strong><?php
  529.             $winner = array_slice($fastestTimes['overall'], 0, 1);
  530.             echo key($winner) ?></strong> <?php echo printSeconds(current($winner)) ?>.</p>
  531.     <?php
  532.         if (count($parameterSets) > 1) {
  533.             echo '<ul>';
  534.             foreach ($fastestTimes as $set => $functions) {
  535.                 if ($set !== 'overall') {
  536.                     echo '<li><b>' . $set . '</b>: ';
  537.                     $setWinner = array_slice($functions, 0, 1);
  538.                     echo key($setWinner) . ' ' . printSeconds(current($setWinner)) . '</li>';
  539.                 }
  540.             }
  541.             echo '</ul>';
  542.         }
  543.     ?>
  544.     </div>
  545.     <div id="resultGraph" style="min-width: 310px; min-height: 400px; margin: 0 auto"></div>
  546.     <h2>Parameter Sets</h2>
  547.     <?php
  548.         foreach ($times as $setName => $functionData) {
  549.             echo '<h3>' , ucfirst($setName) , '</h3>',
  550.                 '<p>' , $parameterSets[$setName]['description'] , '</p>',
  551.                 '<ul>';
  552.             foreach ($functionData as $function => $time) {
  553.                 $identifier = $setName . '-' . $function;
  554.                 echo '<li><a style="text-decoration: none" href="#', $identifier, '">',
  555.                     ucfirst($function),
  556.                     '</a> ',
  557.                     ': ',
  558.                     sprintf('<span style="min-width: 33px; display: inline-block; text-align: right; font-weight: bold;">%1.2d%%</span> ', $time * 100 / $baselineTimes[$setName]),
  559.                     sprintf('<span style="min-width: 50px; display: inline-block; text-align: right; margin: 0 10px;">%s</span> ', printSeconds($time)),
  560.                     $descriptions[$function],
  561.                     '</li>';
  562.             }
  563.             echo '</ul><h4>Parameters</h4><ul>';
  564.             foreach ($parameterSets[$setName] as $key => $value) {
  565.                 if ($key !== 'description') {
  566.                     if (is_array($value)) {
  567.                         echo '<li>' , $key , ':', '</li>'; var_dump($value);
  568.                     } else {
  569.                         echo '<li>' . $key . ' = ' . (string) $value . '</li>';
  570.                     }
  571.                 } else {
  572.                     $setDescriptions[] = $value;
  573.                 }
  574.             }
  575.             echo '</ul>';
  576.         }
  577.     ?>
  578.     <script>
  579.         /**
  580.          * Format an integer as a time value
  581.          *
  582.          * @param {String} time The value to format in microseconds.
  583.          * @param {Number} decimals The amount of decimals
  584.          *
  585.          * @return string
  586.          */
  587.         function printSeconds(time, decimals) {
  588.            decimals = typeof decimals !== 'undefined' ? decimals : 2;
  589.             var prefix = '',
  590.                 suffix = 'μs';
  591.             if (time < 0) {
  592.                 time = Math.abs(time);
  593.                 prefix = '-';
  594.             }
  595.             if (time == 0) {
  596.                 suffix = '';
  597.             }
  598.             if (time >= 1000) {
  599.                 time = time / 1000;
  600.                 suffix = 'ms';
  601.             }
  602.             if (time >= 1000) {
  603.                 time = time / 1000;
  604.                 suffix = ' s';
  605.             }
  606.             if (time >= 60 && suffix == ' s') {
  607.                 time = time / 60;
  608.                 suffix = 'min!';
  609.             }
  610.             return prefix + Highcharts.numberFormat(time, decimals) + ' ' + suffix;
  611.         }
  612.  
  613.         var baseLineTimes = [<?php echo implode(',', $baselineTimes) ?>];
  614.         var descriptions = ['<?php echo implode("','", array_map('addslashes', $descriptions)) ?>'];
  615.         var setDescriptions = ['<?php echo implode("','", array_map('addslashes', $setDescriptions)) ?>'];
  616.         jQuery(document).ready(function($) {
  617.             $('#resultGraph').highcharts({
  618.                 chart: {
  619.                     zoomType: 'y'
  620.                 },
  621.                 title: {
  622.                     text: '<?php echo $testName ?>'
  623.                 },
  624.                 xAxis: {
  625.                     categories: ['<?php echo implode("','", $xAxis)  ?>'],
  626.                     title: {
  627.                         text: null
  628.                     }
  629.                 },
  630.                 yAxis: {
  631.                     min: 0,
  632.                     title: {
  633.                         text: 'Time (milliseconds)',
  634.                         align: 'high'
  635.                     },
  636.                     labels: {
  637.                         overflow: 'justify',
  638.                         formatter: function() {
  639.                             return printSeconds(this.value);
  640.                         }
  641.                     }
  642.                 },
  643.                 tooltip: {
  644.                     useHTML: true,
  645.                     formatter: function() {
  646.                         return '<strong><a style="text-decoration: none" href="#' + this.point.series.name + '-' + this.point.category + '">' + this.point.series.name + ', ' + descriptions[this.point.x] + '</a></strong><br/>' +
  647.                             setDescriptions[this.series.index] + '<br/>' +
  648.                             printSeconds(this.point.y) +
  649.                             ' (' + Math.ceil(this.point.y * 100 / baseLineTimes[this.point.series.index]) + '%)';
  650.                     }
  651.                 },
  652.                 legend: {
  653.                     enabled: true
  654.                 },
  655.                 credits: {
  656.                     enabled: false
  657.                 },
  658.                 series: [
  659.                     <?php
  660.                     foreach ($times as $setName => $setTimes) {
  661.                         $series[] = "{
  662.                             name: '" . $setName . "',
  663.                             data: [" . implode(',', $setTimes) . "]
  664.                         }";
  665.                     }
  666.                     echo implode(',', $series);
  667.                     ?>
  668.                 ]
  669.             });
  670.             $('#showSourceLink').on('click', function(e) {
  671.                 e.preventDefault();
  672.                 $.ajax({
  673.                     url: '<?php echo $_SERVER['SCRIPT_NAME'] ?>?source=1',
  674.                     cache: false
  675.                 })
  676.                 .done(function(html) {
  677.                     $('.loading').hide();
  678.                     $('#sourceCode').html(html);
  679.                     $('html, body').animate({
  680.                         scrollTop: $("#source").offset().top
  681.                     }, {
  682.                         duration: 2000,
  683.                         easing: 'easeOutBounce'
  684.                     });
  685.                 });
  686.             });
  687.             $('.top').on('click', function(e) {
  688.                 e.preventDefault();
  689.                 $('html, body').animate({
  690.                     scrollTop: $("#top").offset().top
  691.                 }, {
  692.                     duration: 2000,
  693.                     easing: 'easeOutBounce'
  694.                 });
  695.             });
  696.         });
  697.     </script>
  698.     <h2>Data results</h2>
  699.     <?php
  700.         foreach ($times as $setName => $functionData) {
  701.             echo '<h3>' . ucfirst($setName) . '</h3>';
  702.             echo '<p>' . $parameterSets[$setName]['description'] . '</p>';
  703.             echo '<ul>';
  704.             foreach ($parameterSets[$setName] as $key => $value) {
  705.                 if ($key !== 'description') {
  706.                     if (is_array($value)) {
  707.                         echo '<li>' , $key , ':', '</li>'; var_dump($value);
  708.                     } else {
  709.                         echo '<li>' . $key . ' = ' . (string) $value . '</li>';
  710.                     }
  711.                 }
  712.             }
  713.             echo '</ul>';
  714.             foreach ($functionData as $function => $time) {
  715.                 echo '<h4 id="', $setName . '-' . $function, '">', ucfirst($function), '</h4>',
  716.                     '<p>', $descriptions[$function], '</p>';
  717.                 var_dump($resultObjects[$setName][$function]);
  718.             }
  719.         }
  720.     ?>
  721.     <div id="p-personal" role="navigation" class="">
  722.         <ul>
  723.     <?php
  724.     foreach ($resultObjects as $setName => $functionData) {
  725.         foreach ($functionData as $function => $data) {
  726.             echo '<li><a href="#' . $setName . '-' . $function . '">' . ucfirst($setName) . ' - ' . ucfirst($function)  . '</a></h3>';
  727.         }
  728.     }
  729.     ?>
  730.             <li><a href="#about">About - v<?php echo $v ?></a></li>
  731.             <li><a href="#help">Help</a></li>
  732.             <li><a href="#source">Source Code</a></li>
  733.         </ul>
  734.     </div>
  735.     <div id="help">
  736.     <div id="about">
  737.         <h2>About</h2>
  738.         <p>Tiny TYPO3 Test Suite v<?php echo $v ?> is a script that helps you test different method implementations. Get the latest version from github:
  739.             <a href="https://github.com/Tuurlijk/TinyTypo3TestSuite">https://github.com/Tuurlijk/TinyTypo3TestSuite</a></p>
  740.     </div>
  741.         <h2>Help</h2>
  742.         <h3>Execution Order</h3>
  743.         <p>In some cases, the second function (non baseline) always runs faster than the baseline. Even when switching the code around. This toggle enables you to reverse the running order to check for this behaviour. Your winning function should still win whatever the execution order. If that is not the case, then this test has failed to determine what code runs faster.</p>
  744.     </div>
  745.     <div id="source">
  746.         <h2>Source Code</h2>
  747.         <pre id="sourceCode"><a href="#source" id="showSourceLink">Show the sourcecode of this file.</a></pre>
  748.     </div>
  749.     <a href="#top" class="top" style="position: fixed; bottom: 10px; left: 25px; text-decoration: none;">^ top</a>
  750.     <a href="https://github.com/Tuurlijk/TinyTypo3TestSuite"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png" alt="Fork me on GitHub"></a>
  751.     <div id="logo" style="position: absolute; top: 60px; left: 60px;"><img alt="" src="data:image/png;base64,
  752. iVBORw0KGgoAAAANSUhEUgAAAHYAAAAiCAYAAACKuC3wAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ
  753. bWFnZVJlYWR5ccllPAAABzJJREFUeNrsWwlsFUUYHh4VkEMEKaACHmAV0KTENFxaiIqK1sQDNYIS
  754. UTQRDSlH1DSIBqSgAQVijGIEjdYDREXEIEo4LSiKgFgUMKCAIK1KFQoUSv1++y/v7zCzZ1/bkP2T
  755. Lztv59jd+Wb+a/c1qKysVLGcftLAb8PKfNUQh8sYRxrkqUWGNpNweBhoI06XAiXALuBnoBBYgv77
  756. 4umvA2JBEtVlATcA13K5KVf3ADEbtPadcdju87rHgY+BURhnd0xDzUuagdAMHIYDg4HzDX3+1kll
  757. 6RjwuoOAnrje5Rjvn5iKFBGLCSYV+yxwu4eKtpFwIMT1aTHcCMyNqUgBsSB1NA75QGMffc6xnP89
  758. 1XY+Fv+SAKmP4DjNJ6kkzdGnwyns5Kn9OISxl3/FNKSAWODREP36Wc5/FWKsXTENqSG2W4h+11jO
  759. Lwo4zkFga0xDamxsGBt3PYVDUL96duMToBxo5HOc7zHGCUtda2B8iHtbAXzEjmBzseC+8Og3Asgw
  760. tD8TmAq04nCvMZ+juSsD9gLLOHzz40CeAdxGcwhczOORQ7qZnch1Ln3p+rdQuAlcAqQL/2Y58BZw
  761. 6H/TCIIogXBWiAnsC1IKDeHSh3zjfuQJjPG8pe5CYEeI+5oB5DIZY/jcFqA73Z6lTyfgFyarAqCY
  762. /FeuO5tCPJ++wgPAApc2GbwAurq0IXIeAo4a6jJpM7j03QYMoHtPhJw8kiEuE+tXFqZQG01j7aF4
  763. InNc2o4Wod/bglSTlPAEbgQ2iGuQhvkA6GXp14q1gCSVHM4iNkmO3AfM8vF8tNh+4gXpCO3i2Y6N
  764. LQo5cXdidzYyeMekCtf76L8Obbe41JOHfZEBss89hvoJXEcqco7UDi4qf7ijcIApHvedzjsvk1Ui
  765. JXFWC9M23dLvKdYMzuIgP6Uda5J07f6GAlcZxvhNVWUC2/J90yLpwmq9Qvg/3YjYNSGJTefskUny
  766. fPR/2aOe0o47DSgXbfYZ6mX4NFU8cF+GLhQVNOPyXN4FQaSEiXB8hZ7CVjtCdvRB8fsxtsuOHAHI
  767. JL2v3ZdJ3S8BirXzpAnmi9/ZROzKCOou15hxyFOf47DYpR+tvHdqwTmk3PU8l11LTtBI8XtKyOvs
  768. YLXsiK6Os4QfU8wq22uxXxfwHr4W5S5E7KYIWaMsqOM+Ll7mQUvdOJBfXkue/2RRztHCu2Eq+SZq
  769. oUZOUNmqOX5Semtee4VLHuAYl9uwmg2T6GmR4JAlihMzzrJrd7AjoIczi9lBqS3ZJOJrCu3GCns4
  770. VrTLj3gdObEttbpLRflHlzEqNFOQEeD6zUW5PMGFeREeaCB2bbaFXHLt71JV72QV3/RQQ/ybapGk
  771. 3csOzx3sbJF8CayNeI2GoqyHKvItmZd23CPKHQJcXy6e3Q6xyyOoY1fbBBLJqF/ANuNK/C6ug0RM
  772. ofAlKEEwSrO3k2rgGvLjgkNaXVvLzvba+e18XrsZL1RHViV48iu00CCo9MauHeJCbimwFCirwyzb
  773. ZM3p68HlNbywo0qmxd6SNBHlfz3GKdOyVCZpz3a8M4c65KyeK+x0YUI0ft0lM+NHpoPc9qr+ymKR
  774. tZFqc0INjN2PJ9mRtYYdZVPTusjdbssIvsee+HYmta/wjO92EhTS2VkQURUVgNy0ekzuZO33Bp6Y
  775. sELzR58NFYhzpPLr6o1Ve8cDT2gVL0QcmLIec/jDt/oo87XgfkYILXVAoJwdL8c5olBlTA3er+0F
  776. yUvsJxCeFjEs+TLvUkiXptnCVSBlhbK/b/Uj5HV2wjjjeeUexbh76gmxJzQbFuZznpaW8/Ss9BLg
  777. W0NdqZaF8nKEHLF9hqQnOCaqqjdrORzGjTCpzWe0dFcYyWaHhB6oqzq95E1RPqyqEvmFPGe2pIs8
  778. 38Jj/KaWfm5CWmemSr7o6J9m8GCXY7d9huJNNTAJuRhv72lG7P0h+vwhyq092sr6IN9e/yDKXRKW
  779. RhTjHY9qz0DqGyoWPSlxnkdbmcwIsimqqfuEJe6kt/kvRniQnSr5KiyW6mnC7i7tyOnMsPTzkiO6
  780. u24TsrXbQjwExWG3YnEciPk8Kd+I8tUu895LOFclKthHEDL9WJpwyRaVsYd7LKDXOQR9N8ZcVpPv
  781. hIdLacKBlnbDRHlpwGsMEOVtbjuWyKWVNjIAqZTgXxDzeIoc5vjSkekGW3uz5pjNNoxDb3CaGM53
  782. ZA17MkmS8LojEPUKDs95NDvGpBbEHFplooib6T0rpQPpw79XgVXApyqZ6qRs2BLDGIPY1FHflRzP
  783. Ejar5H+nyOl9zVf6D4Q9iRCojFeF/rkqfZs0mJIbMXeuQkka+l8UvcqkHDB9vWH6mnM9m0Cb0Gbs
  784. rKrnpqU8Tk5Xwu9dgThKllPKcDUHxOTC0+u6K2qZVPqP7UbGwRD9i0T/Uh/tK0T7qL7DMvaKSRVv
  785. VcmUIanqNWz2+rDjZLPVs7jtfpVMh/6pqjJP/Z1o5j8BBgADhL1q2hRfzwAAAABJRU5ErkJggg==" /></div>
  786. </div>
  787. </body>
  788. </html>
Add Comment
Please, Sign In to add comment