getTime() public method

Returns the elapsed time, readable or not
public getTime ( $raw = false, string $format = null ) : string | float
$format string The format to display (printf format)
return string | float
Esempio n. 1
0
 public function testGetTime()
 {
     $bench = new Ubench();
     $bench->start();
     $bench->end();
     $this->assertRegExp('/^[0-9.]+ms/', $bench->getTime());
     $bench = new Ubench();
     $bench->start();
     sleep(2);
     $bench->end();
     $this->assertRegExp('/^[0-9.]+s/', $bench->getTime());
     $this->assertInternalType('float', $bench->getTime(true));
     $this->assertRegExp('/^[0-9]+s/', $bench->getTime(false, '%d%s'));
 }
Esempio n. 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;
}
Esempio n. 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());
 }
Esempio n. 4
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";
}
Esempio n. 5
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());
    });
    $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
Esempio n. 7
0
 * 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;
 /**
  * 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");
 }
Esempio n. 9
0
</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();
?>

</body>
</html>

Esempio n. 10
0
<?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";
Esempio n. 11
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>';
 }
Esempio n. 12
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