当前位置: 首页>>代码示例>>PHP>>正文


PHP benchmark函数代码示例

本文整理汇总了PHP中benchmark函数的典型用法代码示例。如果您正苦于以下问题:PHP benchmark函数的具体用法?PHP benchmark怎么用?PHP benchmark使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了benchmark函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: benchmark_many

function benchmark_many($iterations = 10)
{
    $res = ['json' => 0, 'yaml' => 0];
    for ($i = 0; $i < $iterations; ++$i) {
        $stats = benchmark(generate_complex_array());
        $res['json'] += $stats['json'];
        $res['yaml'] += $stats['yaml'];
    }
    $res['json'] /= $iterations;
    $res['yaml'] /= $iterations;
    return $res;
}
开发者ID:djfm,项目名称:json_vs_yaml_perf,代码行数:12,代码来源:index.php

示例2: benchmark

function benchmark(Benchmark $benchmark, array $configs, &$result)
{
    global $recursion;
    $benchmarkCase = getenv('BENCHMARK_CASE') ?: null;
    foreach ($configs as $case => $config) {
        if ($benchmarkCase === $case || null === $benchmarkCase) {
            try {
                $result[] = $benchmark->run($config);
            } catch (\Doctrine\DBAL\Exception\ConnectionException $ex) {
                if ($recursion > 10) {
                    throw $ex;
                }
                $recursion++;
                trigger_error($ex->getMessage(), E_USER_NOTICE);
                trigger_error("Waiting for database ...", E_USER_NOTICE);
                sleep(10);
                benchmark($benchmark, $configs, $result);
            }
        }
    }
}
开发者ID:prooph,项目名称:event-store-adapter-benchmarks,代码行数:21,代码来源:run_benchmark.php

示例3: function

 * @param $ary
 * @param array $keyStack
 */
$iterateWithoutIterator = function (&$ary, $keyStack = array()) {
    global $iterateWithoutIterator;
    $keyValues = array();
    foreach ($ary as $key => $value) {
        if (!is_array($value)) {
            $nestedKey = implode('.', array_merge($keyStack, array($key)));
            $keyValues[$nestedKey] = $value;
        } else {
            $keyStack2 = $keyStack;
            $keyStack2[] = $key;
            $keyValues = array_merge($keyValues, $iterateWithoutIterator($value, $keyStack2));
        }
    }
};
function benchmark($f, $ary, $title = '', $iterations = 10000)
{
    echo '<br><b>', $title, '</b><br>';
    $start = microtime(true);
    for ($i = 0; $i < $iterations; $i++) {
        $f($ary);
    }
    $time = microtime(true) - $start;
    echo 'Time: ', $time, '<br>';
    echo 'Average: ', $time / $iterations, '<br>';
}
benchmark($iterateWithIterator, $ary, 'With Iterator');
benchmark($iterateWithoutIterator, $ary, 'Without Iterator');
开发者ID:akiu,项目名称:NoobieFramework,代码行数:30,代码来源:iterator.php

示例4: benchmark

end
ENDIR;
/**
 * Compile the function using the JITFU extension!
 *
 * This is extremely cheap, since no analysis needs to happen. All that happens is the IR
 * is turned into JIT-Fu instructions (which are then compiled by libjit).
 */
$func = Jit::getInstance()->compileIrJitFu($ir, 'fibo');
/**
 * Now let's benchmark the two implementations!
 *
 * If you don't have JitFu installed, then both should be equal.
 */
benchmark("fibo", "PHP");
benchmark($func, "ReckiCT");
/**
 * A very light weight benchmark tool, which runs the code 100,000 times.
 *
 * @param callable $func  The function to benchmark
 * @param string   $label The label of the test, for output
 *
 * @return void
 */
function benchmark(callable $func, $label)
{
    $start = microtime(true);
    $result = $func(30);
    $end = microtime(true);
    printf("%s completed fibo(30)=={$result} in %01.4F seconds\n", $label, $end - $start);
}
开发者ID:bwoebi,项目名称:recki-ct,代码行数:31,代码来源:03-fibo-using-ir.php

示例5: benchmark

<?php

require 'vendor/autoload.php';
function benchmark($name, $runs, $function)
{
    $start = microtime(true);
    while ($runs--) {
        $function();
    }
    $end = microtime(true);
    return sprintf('%s: %s', $name, $end - $start) . PHP_EOL;
}
function heavyCalc($varA, $varB)
{
    usleep(100);
    return $varA + $varB;
}
$memoized = Knlv\memoize('heavyCalc');
echo benchmark('heavyCalc(1, 2)', 100, function () {
    heavyCalc(1, 2);
});
echo benchmark('Memoized heavyCalc(1, 2)', 100, function () use(&$memoized) {
    $memoized(1, 2);
});
开发者ID:kanellov,项目名称:memoize,代码行数:24,代码来源:benchmark.php

示例6: benchmark

benchmark('invoke', $array, $iterator, $hash, $hashIterator, 'method');
benchmark('last', $array, $iterator, $hash, $hashIterator, function ($v, $k) {
    return $v > 1000;
});
benchmark('map', $array, $iterator, $hash, $hashIterator);
benchmark('none', $array, $iterator, $hash, $hashIterator);
benchmark('partition', $array, $iterator, $hash, $hashIterator, function ($v, $k) {
    return $v / 2;
});
benchmark('pluck', $array, $iterator, $hash, $hashIterator, 'property');
benchmark('product', $array, $iterator, $hash, $hashIterator, false);
benchmark('ratio', $array, $iterator, $hash, $hashIterator, false);
benchmark('reduce_left', $array, $iterator, $hash, $hashIterator, function ($v) {
    return $v;
});
benchmark('reduce_right', $array, $iterator, $hash, $hashIterator, function ($v) {
    return $v;
});
benchmark('reject', $array, $iterator, $hash, $hashIterator);
benchmark('select', $array, $iterator, $hash, $hashIterator);
benchmark('some', $array, $iterator, $hash, $hashIterator);
benchmark('sum', $array, $iterator, $hash, $hashIterator, false);
benchmark('difference', $array, $iterator, $hash, $hashIterator, false);
benchmark('ratio', $array, $iterator, $hash, $hashIterator, false);
benchmark('product', $array, $iterator, $hash, $hashIterator, false);
benchmark('average', $array, $iterator, $hash, $hashIterator, false);
benchmark('first_index_of', $array, $iterator, $hash, $hashIterator, 2000);
benchmark('last_index_of', $array, $iterator, $hash, $hashIterator, 2000);
benchmark('head', $array, $iterator, $hash, $hashIterator);
benchmark('tail', $array, $iterator, $hash, $hashIterator);
开发者ID:RightThisMinute,项目名称:responsive-images-php,代码行数:30,代码来源:suite.php

示例7: html_my_layout

function html_my_layout($vars){ extract($vars);?> 
<html>
<head>
	<title>Limonde second example</title>
</head>
<body>
  <h1>Limonde second example: errors</h1>
	<?php echo $content?>
	<hr>
	<p>
	<a href="<?php echo url_for('/')?>">Home</a> |
	<a href="<?php echo url_for('/everything/is_going_wrong')?>">everything is going wrong</a> | 
	<a href="<?php echo url_for('/welcome/')?>">Welcome !</a> | 
	<a href="<?php echo url_for('/welcome/bill')?>">Welcome Bill ?</a> | 
	<a href="<?php echo url_for('/welcome/leland')?>">Welcome Leland ?</a> | 
	<a href="<?php echo url_for('/welcome/bob')?>">Welcome Bob ?</a> | 
	<a href="<?php echo url_for('/welcome/david')?>">Welcome David ?</a> | 
	<a href="<?php echo url_for('/welcome/audrey')?>">Welcome Audrey ?</a> | 
	</p>
</body>
</html>
<!--
<?php print_r(benchmark()); ?>
-->
<?};
开发者ID:htom78,项目名称:limonade,代码行数:25,代码来源:index.php

示例8: foreach

    // Determine the average runtime across all trials.
    foreach ($results['t'] as &$result) {
        $result /= TRIALS;
    }
    return $results;
}
$results = [];
echo "Generating benchmarks...\n";
// Run each benchmark in the schedule.
foreach ($schedule as $name => $batches) {
    $results[$name] = $results[$name] ?? [];
    foreach ($batches as $batchId => $batch) {
        $results[$name][$batchId] = [];
        list($range, $candidates) = $batch;
        if (count($candidates) === 0) {
            continue;
        }
        echo "\n\t{$name}:";
        foreach ($candidates as $candidate) {
            echo "\n\t\t{$candidate} ";
            list($type, $functions) = $config[$name];
            $functions = $functions[$candidate];
            // Benchmark this task according to its setup, tick and reset functions.
            $results[$name][$batchId][$candidate] = benchmark($type, $range, ...$functions);
        }
        echo "\n";
    }
}
// This will be the path that the reporter will use.
$results_path = __DIR__ . '/results.json';
file_put_contents($results_path, json_encode($results, JSON_PRETTY_PRINT));
开发者ID:php-ds,项目名称:benchmarks,代码行数:31,代码来源:generator.php

示例9: isset

<?php

require_once __DIR__ . '/common.php';
$num = isset($argv[1]) ? $argv[1] : 1000;
printf("creating %d test domain objects\n", $num);
benchmark($num, function () {
    $rel = new TestRelationship();
    $object = new TestObject();
    $object->TestRel = $rel;
    $rel->save();
    $object->save();
});
开发者ID:lox,项目名称:pheasant,代码行数:12,代码来源:bench_create.php

示例10: foreach

    foreach ($args as $arg) {
        $total += $arg;
        $count++;
    }
    return $total / $count;
}
function average2(...$args)
{
    $total = 0;
    $count = 0;
    foreach ($args as $arg) {
        $total += $arg;
        $count++;
    }
    return $total / $count;
}
$arr = [1, 2, 3, 4, 5];
echo "Step1. func_get_args() vs ... \n";
echo benchmark(function () {
    average1(1, 2, 3, 4, 5);
}, 10000), "\n";
echo benchmark(function () {
    average2(1, 2, 3, 4, 5);
}, 10000), "\n";
echo "Step2. call_user_func_array() vs ... \n";
echo benchmark(function () use($arr) {
    call_user_func_array('average2', $arr);
}, 10000), "\n";
echo benchmark(function () use($arr) {
    average2(...$arr);
}, 10000), "\n";
开发者ID:eunicon,项目名称:meetup,代码行数:31,代码来源:05new_expression_benchmark.php

示例11: on_exit

function on_exit()
{
    execute_hook('content_end');
    benchmark('Everything Done. Will send output to template.php');
    benchmark(NULL, true);
    $ctrl = global_var('controller');
    while ($ctrl !== false) {
        $ctrl = substr($ctrl, 0, strrpos($ctrl, '/'));
        $template = config('base_path') . 'app/' . $ctrl . '/_template.php';
        if (file_exists($template)) {
            global_var('template_file', $template, 1);
            include $template;
            break;
        }
    }
    if (!isset($_SESSION['new_flash'])) {
        $_SESSION['new_flash'] = array();
    }
    $_SESSION['flash'] = $_SESSION['new_flash'];
    unset($_SESSION['new_flash']);
    execute_hook('exit');
}
开发者ID:1upon0,项目名称:ui,代码行数:22,代码来源:ui.php

示例12: array

    $collection = array();
    for ($i = 0; $i < 50; $i++) {
        $collection[] = createObject();
    }
    return $collection;
}
function createObject()
{
    $post = new \JMS\Serializer\Tests\Fixtures\BlogPost('FooooooooooooooooooooooBAR', new \JMS\Serializer\Tests\Fixtures\Author('Foo'), new \DateTime());
    for ($i = 0; $i < 10; $i++) {
        $post->addComment(new \JMS\Serializer\Tests\Fixtures\Comment(new \JMS\Serializer\Tests\Fixtures\Author('foo'), 'foobar'));
    }
    return $post;
}
$serializer = \JMS\Serializer\SerializerBuilder::create()->build();
$collection = createCollection();
$metrics = array();
$f = function () use($serializer, $collection, $format) {
    $serializer->serialize($collection, $format);
};
// Load all necessary classes into memory.
benchmark($f, 1);
printf('Benchmarking collection for format "%s".' . PHP_EOL, $format);
$metrics['benchmark-collection-' . $format] = benchmark($f, $iterations);
$output = json_encode(array('metrics' => $metrics));
if (isset($_SERVER['argv'][3])) {
    file_put_contents($_SERVER['argv'][3], $output);
    echo "Done." . PHP_EOL;
} else {
    echo $output . PHP_EOL;
}
开发者ID:corcre,项目名称:elabftw,代码行数:31,代码来源:benchmark.php

示例13: isset

<?php

require_once __DIR__ . '/common.php';
$num = isset($argv[1]) ? $argv[1] : 10000;
$binder = new \Pheasant\Database\Binder();
$binds = array(array('SELECT * FROM table WHERE column=?', array('test')), array('x=?', array('10\'; DROP TABLE --')), array('column1=? and column2=?', array(false, true)), array("name='???' and llamas=?", array(24)), array("name='\\'7r' and llamas=?", array(24)), array("name='\\'7r\\\\' and another='test question?' and llamas=?", array(24)), array("name='\\'7r\\\\' and x='\\'7r' and llamas=?", array(24)));
printf("binding %d statements %d times\n", count($binds), $num);
benchmark($num, function () use($binds, $binder) {
    foreach ($binds as $bind) {
        $binder->bind($bind[0], $bind[1]);
    }
});
开发者ID:lox,项目名称:pheasant,代码行数:12,代码来源:bench_binding.php

示例14: createCollection

    }
    return $post;
}
$serializer = \Kcs\Serializer\SerializerBuilder::create()->setEventDispatcher(new \Symfony\Component\EventDispatcher\EventDispatcher())->build();
$collection = createCollection();
$metrics = [];
$f = function ($format) use($serializer, $collection) {
    $serializer->serialize($collection, $format);
};
// Load all necessary classes into memory.
$f('array');
$table = new \Symfony\Component\Console\Helper\Table($output);
$table->setHeaders(['Format', 'Direction', 'Time']);
$progressBar = new \Symfony\Component\Console\Helper\ProgressBar($output, 8);
$progressBar->start();
foreach (['array', 'json', 'yml', 'xml'] as $format) {
    $table->addRow([$format, 'serialize', benchmark($f, $format)]);
    $progressBar->advance();
}
$serialized = ['array' => $serializer->serialize($collection, 'array'), 'json' => $serializer->serialize($collection, 'json'), 'yml' => $serializer->serialize($collection, 'yml'), 'xml' => $serializer->serialize($collection, 'xml')];
$type = new \Kcs\Serializer\Type\Type('array', [\Kcs\Serializer\Type\Type::from(\Kcs\Serializer\Tests\Fixtures\BlogPost::class)]);
$d = function ($format) use($serializer, $serialized, $type) {
    $serializer->deserialize($serialized[$format], $type, $format);
};
foreach (['array', 'json', 'yml', 'xml'] as $format) {
    $table->addRow([$format, 'deserialize', benchmark($d, $format)]);
    $progressBar->advance();
}
$progressBar->finish();
$progressBar->clear();
$table->render();
开发者ID:alekitto,项目名称:serializer,代码行数:31,代码来源:benchmark.php

示例15: strtolower

}
$file = $argv[1];
$extension = strtolower(substr($file, strrpos($file, '.') + 1));
$out = tempnam($config['tmp'], 'thumb');
$count = 300;
function benchmark($method)
{
    global $config, $file, $extension, $out, $count;
    $config['thumb_method'] = $method;
    printf("Method: %s\nThumbnailing %d times... ", $method, $count);
    $start = microtime(true);
    for ($i = 0; $i < $count; $i++) {
        $image = new Image($file, $extension);
        $thumb = $image->resize($config['thumb_ext'] ? $config['thumb_ext'] : $extension, $config['thumb_width'], $config['thumb_height']);
        $thumb->to($out);
        $thumb->_destroy();
        $image->destroy();
    }
    $end = microtime(true);
    printf("Took %.2f seconds (%.2f/second; %.2f ms)\n", $end - $start, $rate = $count / ($end - $start), 1000 / $rate);
    unlink($out);
}
benchmark('gd');
if (extension_loaded('imagick')) {
    benchmark('imagick');
} else {
    echo "Imagick extension not loaded... skipping.\n";
}
benchmark('convert');
benchmark('gm');
becnhmark('convert+gifsicle');
开发者ID:0151n,项目名称:vichan,代码行数:31,代码来源:benchmark.php


注:本文中的benchmark函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。