getMemoryUsage() public méthode

Returns the memory usage at the end checkpoint
public getMemoryUsage ( $raw = false, string $format = null ) : string | float
$format string The format to display (printf format)
Résultat string | float
 public function testGetMemoryUsage()
 {
     $bench = new Ubench();
     $bench->start();
     $bench->end();
     $this->assertRegExp('/^[0-9.]+Mb/', $bench->getMemoryUsage());
     $this->assertInternalType('integer', $bench->getMemoryUsage(true));
     $this->assertRegExp('/^[0-9]+Mb/', $bench->getMemoryUsage(false, '%d%s'));
 }
Exemple #2
0
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;
}
Exemple #3
0
 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());
 }
    });
    $app->any('/def/{id}/{name}', ["admin", "middleware"], function () {
    });
    $app->any('/defg/{id}/{what}', function () {
    }, ["admin", "middleware"]);
    $app->any('/def/def/{shit}', ["admin", "action"], ['admin', 'middleware']);
    $app->any('/def/3/{zzz}', ["admin", "middleware"], ['admin', 'action'], function () {
    });
    try {
        $app->dispatch($getMock);
    } catch (RuntimeException $e) {
    }
}
/****************************************************************/
$bench->end();
// Get elapsed time and memory
echo $bench->getTime() . "\n";
// 156ms or 1.123s
echo $bench->getTime(true) . "\n";
// elapsed microtime in float
echo $bench->getTime(false, '%d%s') . "\n";
// 156ms or 1s
echo $bench->getMemoryPeak() . "\n";
// 152B or 90.00Kb or 15.23Mb
echo $bench->getMemoryPeak(true) . "\n";
// memory peak in bytes
echo $bench->getMemoryPeak(false, '%.3f%s') . "\n";
// 152B or 90.152Kb or 15.234Mb
// Returns the memory usage at the end mark
echo $bench->getMemoryUsage() . "\n";
// 152B or 90.00Kb or 15.23Mb
 *
 * (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);
printf("Memory Usage Comparison: \n");
printf("Whole -> %s\n", $wholeUseCase);
printf("Iterator -> %s\n", $iteratorUseCase);
printf("Ratio: 1:%s (whole vs iterator) \n", ceil($iteratorUseCaseBytes / $wholeUseCaseBytes * 100));
 /**
  * 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");
 }
 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>';
 }
Exemple #8
0
<?php

////////////////////////////////////////////////////
// Benchmark Example
////////////////////////////////////////////////////
$bench = new Ubench();
$bench->start();
// Execute some code
for ($i = 0; $i < 10000000; $i++) {
    $i++;
}
$bench->end();
// Get elapsed time and memory
$nl = "<br>";
echo $bench->getTime() . $nl;
// 156ms or 1.123s
echo $bench->getTime(true) . $nl;
// elapsed microtime in float
echo $bench->getTime(false, '%d%s') . $nl;
// 156ms or 1s
echo $bench->getMemoryPeak() . $nl;
// 152B or 90.00Kb or 15.23Mb
echo $bench->getMemoryPeak(true) . $nl;
// memory peak in bytes
echo $bench->getMemoryPeak(false, '%.3f%s') . $nl;
// 152B or 90.152Kb or 15.234Mb
// Returns the memory usage at the end mark
echo $bench->getMemoryUsage() . $nl;
// 152B or 90.00Kb or 15.23Mb