示例#1
0
function runBenchmark($n = 10, $options = array())
{
    // Current settings used by Helioviewer.org
    $defaults = array("inter_format" => "PNG", "output_format" => "PNG", "type" => "Imagick::IMGTYPE_GRAYSCALE", "interlace" => "IMagick::INTERLACE_PLANE", "compression" => "IMagick::COMPRESSION_JPEG", "input_quality" => null, "output_quality" => 20, "depth" => 8, "imgstrings" => false, "base64" => false, "use_gd" => true);
    // Replace default options
    $options = array_replace($defaults, $options);
    // Import image builder
    if ($options['imgstrings']) {
        require_once "src/ImageBuilderNew.php";
    } else {
        require_once "src/ImageBuilderOld.php";
    }
    set_time_limit(3000);
    // Run test n times using specified options
    $times = array();
    for ($i = 0; $i < $n; $i++) {
        $start = microtime(true);
        buildImage($options);
        $end = microtime(true);
        $time = $end - $start;
        array_push($times, $time);
    }
    // Print results
    printResults($times, $options);
}
示例#2
0
文件: bizgolf.php 项目: nubs/bizgolf
/**
 * Creates a docker image based on the requested language with the given user script added to the image for execution.
 *
 * @param string $languageName One of the supported languages.
 * @param string $script The file path to the user's submission to test.
 * @param array $constants An array of constants to set.
 * @return array A description of the docker image that was created.
 * @throws Exception if unable to create docker image
 */
function createImage($languageName, $script, array $constants)
{
    $image = loadLanguage($languageName);
    $scriptContents = file_get_contents($script);
    if ($scriptContents === false) {
        throw new \Exception('Failed to read user script.');
    }
    foreach ($constants as $constantName => $constantValue) {
        $scriptContents = $image['addConstant']($scriptContents, $constantName, $constantValue);
    }
    return buildImage($image, ['/tmp/userScript' => $scriptContents]);
}
/**
 * Convert JSON data to HTML table
 *
 * @param $data
 * @param int $child
 * @return string
 */
function buildTable($data, $child = 0)
{
    $table = '';
    $width = '100%';
    $style = '';
    $ctr = 0;
    if ($data) {
        $table = '<table class="table table-striped table-bordered table-hover">';
        $table .= '<tbody>';
        foreach ($data as $key => $value) {
            $table .= '<tr style="background-color:' . trColor($ctr) . '">';
            $table .= '<td class="vert-align-middle">&nbsp;&nbsp;<strong>' . $key . '</strong></td><td class="vert-align-middle">';
            if (is_array($value)) {
                $table .= buildTable($value, 1);
            } elseif (preg_match('/.gif/i', $value) || preg_match('/.png/i', $value) || preg_match('/.jpeg/i', $value) || preg_match('/.jpg/i', $value) || preg_match('/.bmp/i', $value)) {
                $table .= buildImage($value);
            } else {
                $trimmed_key = trim($key);
                if (stripos($trimmed_key, 'is_') === 0 || stripos($trimmed_key, 'has_') === 0 || stripos($trimmed_key, 'can_') === 0 || stripos($trimmed_key, 'was_') === 0) {
                    $table .= '&nbsp;&nbsp;' . $value ? 'true' : 'false';
                } else {
                    $table .= '&nbsp;&nbsp;' . $value;
                }
            }
            $table .= '</td></tr>';
            $ctr++;
        }
        $table .= '</tbody>';
        $table .= '</table>';
    } else {
        $table .= 'Empty array';
    }
    return $table;
}