Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
コード例 #1
0
 public function testGetMemoryPeak()
 {
     $bench = new Ubench();
     $this->assertRegExp('/^[0-9.]+Mb/', $bench->getMemoryPeak());
     $this->assertInternalType('integer', $bench->getMemoryPeak(true));
     $this->assertRegExp('/^[0-9]+Mb/', $bench->getMemoryPeak(false, '%d%s'));
 }
コード例 #2
0
ファイル: UbenchTest.php プロジェクト: yii2song/ubench
 public function testCallableWithArguments()
 {
     $bench = new Ubench();
     $result = $bench->run(function ($one, $two) {
         return $one + $two;
     }, 1, 2);
     $this->assertEquals(3, $result);
     $this->assertNotNull($bench->getTime());
     $this->assertNotNull($bench->getMemoryUsage());
     $this->assertNotNull($bench->getMemoryPeak());
 }
コード例 #3
0
function run($name, callable $callable, $args = array())
{
    mt_srand(0);
    printf("%21s\t", $name);
    for ($i = 0; $i < TRIALS; $i++) {
        $bench = new Ubench();
        $bench->run($callable, $args);
        echo $bench->getTime() . "\t";
    }
    echo "\n";
}
コード例 #4
0
<?php

/**
 * This file is part of Cartesian Product.
 *
 * (c) Marco Garofalo <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
use Nerd\CartesianProduct\CartesianProduct;
require __DIR__ . '/../vendor/autoload.php';
$bench = new Ubench();
$cartesianProduct = new CartesianProduct();
$cartesianProduct->appendSet(array('a', 'b', 'c'))->appendSet(array('d', 'e'))->appendSet(array('f', 'g', 'h'))->appendSet(array('i', 'j'))->appendSet(array('k', 'l'))->appendSet(array('m', 'n'))->appendSet(array('o'))->appendSet(array('p'))->appendSet(array('q', 'r', 's', 't'))->appendSet(array('u', 'v', 'w'))->appendSet(array('x', 'y'))->appendSet(array('z'));
$bench->start();
foreach ($cartesianProduct as $index => $product) {
    printf("[%s] (%s)\n", $index, implode(',', $product));
}
$bench->end();
printf("Time elapsed: %s\n", $bench->getTime());
printf("Memory footprint: %s\n", $bench->getMemoryPeak());
コード例 #5
0
<?php

require dirname(__DIR__) . '/vendor/autoload.php';
use Jicjjang\June\Router;
use Jicjjang\June\Stubs\AdminController;
use Psr\Http\Message\RequestInterface;
$bench = new Ubench();
$bench->start();
/****************************************************************/
$getMock = Mockery::mock(RequestInterface::class);
$getMock->shouldReceive('getMethod')->andReturn('GET');
$getMock->shouldReceive('getUri->getPath')->andReturn('/abc/ded');
for ($i = 0; $i < 1000; $i++) {
    $app = new Router();
    $app->setController('admin', new AdminController());
    $app->get('/abc', function () {
    }, function () {
    });
    $app->get('/abc/{id}/{name}', ["admin", "middleware"], function () {
    });
    $app->get('/abd/{id}/{what}', function () {
    }, ["admin", "middleware"]);
    $app->get('/abc/def', ["admin", "middleware"], ['admin', 'action']);
    $app->get('/abc/ghi', ["admin", "middleware"], ['admin', 'action'], function () {
    });
    $app->get('/def/{id}/2', function () {
    }, function () {
    });
    $app->get('/def/{id}/{name}', ["admin", "middleware"], function () {
    });
    $app->get('/defg/{id}/{what}', function () {
コード例 #6
0
<?php

/**
 * This file is part of Cartesian Product.
 *
 * (c) Marco Garofalo <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
use Nerd\CartesianProduct\CartesianProduct;
require __DIR__ . '/../vendor/autoload.php';
$bench = new Ubench();
$cartesianProduct = new CartesianProduct();
$cartesianProduct->appendSet(array('a', 'b', 'c'))->appendSet(array('d', 'e'))->appendSet(array('f', 'g', 'h'))->appendSet(array('i', 'j'))->appendSet(array('k', 'l'))->appendSet(array('m', 'n'))->appendSet(array('o'))->appendSet(array('p'))->appendSet(array('q', 'r', 's', 't'))->appendSet(array('u', 'v', 'w'))->appendSet(array('x', 'y'))->appendSet(array('z'));
$bench->start();
foreach ($cartesianProduct as $index => $product) {
    // nothing
}
$bench->end();
$iteratorUseCaseBytes = $bench->getMemoryUsage(true);
$iteratorUseCase = $bench->getMemoryUsage();
$bench->start();
$wholeResult = $cartesianProduct->compute();
foreach ($wholeResult as $index => $product) {
    // nothing
}
$bench->end();
$wholeUseCaseBytes = $bench->getMemoryUsage(true);
$wholeUseCase = $bench->getMemoryUsage();
unset($wholeResult);
コード例 #7
0
ファイル: upstream-test.php プロジェクト: kavinsky/vermut
/**
 * Using presaved granularity
 */
$bench = new Ubench();
$bench->start();
$vermut->mark('user:testing', mt_rand(1, 500));
$vermut->sentUpstreamOperations();
$bench->end();
echo "Saving granularity on config: " . $bench->getTime() . PHP_EOL;
/**
 * Single incr op
 */
$bench = new Ubench();
$bench->start();
$vermut->incr('user:visits');
$vermut->sentUpstreamOperations();
$bench->end();
echo "Single incr op: " . $bench->getTime() . PHP_EOL;
/**
 * 100 incr op
 */
$bench = new Ubench();
$bench->start();
$i = 0;
while ($i < 100) {
    $vermut->incr('user:visits' . mt_rand(1, 9));
    $i++;
}
$vermut->sentUpstreamOperations();
$bench->end();
echo "100 incr op: " . $bench->getTime() . PHP_EOL;
コード例 #8
0
ファイル: index.php プロジェクト: compwright/disqus-demo
$app->post('/', function () use($app) {
    $disqus = Disguz::factory(['disqus.keys' => ['api_key' => getenv('DISQUS_API_KEY'), 'api_secret' => getenv('DISQUS_API_SECRET'), 'access_token' => getenv('DISQUS_ACCESS_TOKEN')]]);
    $result = $disqus->threadsCreate(['forum' => getenv('DISQUS_FORUM'), 'title' => $app->request()->post('title')]);
    $app->redirect('/');
});
// List all the posts on a thread
$app->get('/discussion/:threadId', function ($thread) use($app) {
    $disqus = Disguz::factory(['disqus.keys' => ['api_secret' => getenv('DISQUS_API_SECRET')]]);
    $posts = $disqus->postsList(compact('thread'));
    $thread = $disqus->threadsDetails(compact('thread'));
    $app->render('discussion.php', ['posts' => $posts['response'], 'thread' => $thread['response']]);
});
// Create a new post on a thread
$app->post('/discussion/:threadId', function ($thread) use($app) {
    // Create a client and pass an array of configuration data
    $disqus = Disguz::factory(['disqus.keys' => ['api_secret' => getenv('DISQUS_API_SECRET')]]);
    $result = $disqus->postsCreate(['thread' => $thread, 'message' => $app->request()->post('message'), 'author_name' => $app->request()->post('author_name'), 'author_email' => $app->request()->post('author_email')]);
    $app->redirect('/discussion/' . $thread);
});
// Flag an objectionable post
$app->post('/discussion/:threadId/moderate/:postId', function ($thread, $post) use($app) {
    // Create a client and pass an array of configuration data
    $disqus = Disguz::factory(['disqus.keys' => ['api_secret' => getenv('DISQUS_API_SECRET')]]);
    $result = $disqus->postsReport(compact('post'));
    $app->redirect('/discussion/' . $thread);
});
$bench = new Ubench();
$bench->start();
$app->run();
$bench->end();
$app->render('benchmark.php', compact('bench'));
コード例 #9
0
 /**
  * Imports stations information from EDDB
  */
 public function actionStations()
 {
     $eddbApi = Yii::$app->params['eddb']['archive'] . 'stations.json';
     $time = date('d-m-y_h');
     $file = Yii::getAlias('@app') . '/runtime/stations' . $time . '.json';
     // Download the data from EDDB if the data that we have is out of date
     if (!file_exists($file)) {
         $this->stdOut('Systems data from EDDB is out of date, fetching RAW JSON from EDDB');
         $curl = new Curl();
         $curl = new Curl();
         $curl->setOpt(CURLOPT_ENCODING, 'gzip');
         $curl->download($eddbApi, $file);
     }
     $bench = new \Ubench();
     $result = $bench->run(function ($file, $type) {
         $this->importJsonData($file, $type);
     }, $file, 'stations');
     $this->stdOut("Systems import completed\n");
     $this->stdOut($bench->getTime(false, '%d%s') . "\n");
     $this->stdOut($bench->getMemoryPeak(false, '%.3f%s') . "\n");
     $this->stdOut($bench->getMemoryUsage() . "\n");
 }
コード例 #10
0
ファイル: index.php プロジェクト: slavikusq75/HW2
<!DOCTYPE HTML>
<head>
    <meta http-equiv=Content-Type content="text/html; charset=utf-8">
    <title>Генератор псевдонаучных цитат.</title>
</head>
<body>

<?php 
require 'vendor/autoload.php';
require 'functions.php';
$bench = new Ubench();
$bench->start();
$faker = Faker\Factory::create();
//fake quots output
fakequote();
echo '<br>';
echo '<br>';
//fake nicknames output
echo ReleaseName\Release::random();
//fake names output
echo " " . $faker->name;
echo '<br>';
echo '<br>';
$bench->end();
echo "Benchmarked:";
echo '<br>';
echo $bench->getTime();
echo '<br>';
echo $bench->getMemoryPeak();
?>
コード例 #11
0
ファイル: test.php プロジェクト: kielabokkie/unique-id-bench
<?php

require_once 'vendor/autoload.php';
// Change this to the number of ids you want to generate
$count = 10000;
$bench = new Ubench();
$bench->start();
$hashids = new Hashids\Hashids('4w3s0m3');
for ($i = 0; $i <= $count; $i++) {
    $encoded = $hashids->encode($i);
    // var_dump($encoded);
    $decoded = $hashids->decode($encoded);
}
$bench->end();
echo "\n# Hashids\n";
echo sprintf("Time: %s\n", $bench->getTime());
echo "\n============\n";
$bench->start();
$fakeId = new Guidsen\FakeIdentifier\Optimus(15468539, 1296427827, 340274557);
for ($i = 0; $i <= $count; $i++) {
    $encoded = $fakeId->encode($i);
    // var_dump($encoded);
    $decoded = $fakeId->decode($encoded);
}
$bench->end();
echo "\n# FakeIdentifier\n";
echo sprintf("Time: %s\n", $bench->getTime());
echo "============\n\n";
コード例 #12
0
ファイル: image.php プロジェクト: vijayant123/cURLfun
<?php

include 'src/Ubench.php';
$bench = new Ubench();
$bench->start();
header("Content-Type: text/plain");
/*
$x = 200;
$y = 200;

$gd = imagecreatetruecolor($x, $y);

$corners[0] = array('x' => 100, 'y' =>  10);
$corners[1] = array('x' =>   0, 'y' => 190);
$corners[2] = array('x' => 200, 'y' => 190);

$red = imagecolorallocate($gd, 255, 0, 0); 

for ($i = 0; $i < 100000; $i++) {
imagesetpixel($gd, round($x),round($y), $red);
$a = rand(0, 2);
$x = ($x + $corners[$a]['x']) / 2;
$y = ($y + $corners[$a]['y']) / 2;
}
*/
$gd = imagecreatefrompng('../tmp/cap.png');
$x = imagesx($gd);
$y = imagesy($gd);
$str = '';
for ($i = 0; $i < $x; $i++) {
    for ($j = 0; $j < $y; $j++) {
コード例 #13
0
 public function appEnd()
 {
     $this->bench->end();
     echo '<p style="color:#a0a0a0;text-shadow:1px 1px 0 #FFFFFF;text-align:right;font-size:12px;padding-top:10px;">This page used <strong>' . $this->bench->getTime() . '</strong>, <strong>' . $this->bench->getMemoryUsage() . '</strong>.</p>';
 }
コード例 #14
0
ファイル: test.php プロジェクト: gymadarasz/router-benchmark
function testing(Ubench $bench, $requestURI)
{
    $_SERVER['REQUEST_URI'] = $requestURI;
    echo "\n----------------\ntesting for url: [" . $_SERVER['REQUEST_URI'] . "]\n";
    echo "bench gymadarasz/router\n";
    $bench->start();
    gymadarasz_router();
    $bench->end();
    echo "time:\t" . $bench->getTime() . ' (' . $bench->getTime(true) . ')' . PHP_EOL;
    echo "mem:\t" . $bench->getMemoryUsage() . PHP_EOL;
    echo "\nbench nikic/fast-route\n";
    $bench->start();
    nikic_fast_route();
    $bench->end();
    echo "time:\t" . $bench->getTime() . ' (' . $bench->getTime(true) . ')' . PHP_EOL;
    echo "mem:\t" . $bench->getMemoryUsage() . PHP_EOL;
}