Example #1
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());
 }
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";
}
 /**
  * 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");
 }