Пример #1
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = Config::getInstance();
     $times = $input->getOption('times');
     if ($times < 1) {
         $output->writeln("<error>benchmark {$times} is too small</error>");
         return;
     }
     $type = $input->getArgument('type');
     $output->writeln("<info>benchmark {$type}:</info>\t<comment>{$times} times</comment>");
     switch ($type) {
         case 'all':
             foreach ($config->getQueries() as $name => $query) {
                 $this->benchmark($output, $query, $name, $times);
             }
             break;
         case 'file':
             foreach ($config->getQueries() as $name => $query) {
                 if (FileQuery::is_a($query)) {
                     $this->benchmark($output, $query, $name, $times);
                 }
             }
             break;
         case 'database':
             foreach ($config->getQueries() as $name => $query) {
                 if (DatabaseQuery::is_a($query)) {
                     $this->benchmark($output, $query, $name, $times);
                 }
             }
             break;
         default:
             $output->writeln("<error>Unknown type \"{$type}\".</error>");
             break;
     }
 }
Пример #2
0
 /**
  * benchmark
  *
  * @param string $type file or database
  *
  * @throws \Exception
  */
 public function run($type = 'all')
 {
     $times = $this->controller->times;
     if ($times < 1) {
         $this->stderr("benchmark {$times} is too small\n", Console::FG_GREY, Console::BG_RED);
         return;
     }
     $this->stdout("benchmark {$type}:", Console::FG_GREEN);
     $this->stdout("\t{$times} times\n", Console::FG_YELLOW);
     switch ($type) {
         case 'all':
             foreach ($this->ipv4->getQueries() as $name => $query) {
                 $this->benchmark($query, $name, $times);
             }
             break;
         case 'file':
             foreach ($this->ipv4->getQueries() as $name => $query) {
                 if (FileQuery::is_a($query)) {
                     $this->benchmark($query, $name, $times);
                 }
             }
             break;
         case 'database':
             foreach ($this->ipv4->getQueries() as $name => $query) {
                 if (DatabaseQuery::is_a($query)) {
                     $this->benchmark($query, $name, $times);
                 }
             }
             break;
         default:
             $this->stderr("Unknown type \"{$type}\".\n", Console::FG_GREY, Console::BG_RED);
             break;
     }
 }
Пример #3
0
 public function testTranslateId()
 {
     $query0 = new DummyQuery();
     $query0->init();
     $query = new DummyPlusDatabaseQuery(new DummyDatabase());
     DatabaseQuery::initDivision();
     $this->assertFalse($query->exists());
     $query->setProviders([$query0]);
     $query->init();
     $this->assertEquals(5, $query->findId(ip2long('0.0.0.0')));
     $this->assertEquals(1, $query->findId(ip2long('1.0.0.0')));
     $this->assertEquals(1, $query->findId(ip2long('2.0.0.0')));
     $this->assertEquals(1, $query->findId(ip2long('3.0.0.0')));
     $this->assertEquals(1, $query->findId(ip2long('4.0.0.0')));
     $this->assertEquals(1, $query->findId(ip2long('5.0.0.0')));
     $this->assertEquals(1, $query->findId(ip2long('6.0.0.0')));
     $this->assertEquals(4, $query->findId(ip2long('10.0.0.0')));
     $this->assertEquals(3, $query->findId(ip2long('127.0.0.1')));
     $this->assertEquals(4, $query->findId(ip2long('127.0.0.2')));
 }
Пример #4
0
 /**
  * @param OutputInterface $output
  */
 private function cleanDivision(OutputInterface $output)
 {
     $output->write("<info>clean divisions:</info>");
     DatabaseQuery::cleanDivision();
     $output->writeln('<info> completed!</info>');
 }
Пример #5
0
 /**
  *
  */
 protected function division()
 {
     DatabaseQuery::initDivision(function ($code, $n) {
         static $total = 0;
         switch ($code) {
             case 0:
                 $this->stdout("generate divisions table:\n", Console::FG_GREEN);
                 if (empty($this->controller->noProgress)) {
                     Console::startProgress(0, $n);
                 }
                 $total = $n;
                 break;
             case 1:
                 if (empty($this->controller->noProgress)) {
                     Console::updateProgress($n, $total);
                 }
                 break;
             case 2:
                 if (empty($this->controller->noProgress)) {
                     Console::updateProgress($total, $total);
                     Console::endProgress();
                 }
                 $this->stdout(" completed!\n", Console::FG_GREEN);
                 break;
         }
     }, true);
 }
Пример #6
0
 /**
  * @param OutputInterface $output
  * @param bool $noProgress
  */
 protected function division(OutputInterface $output, $noProgress)
 {
     DatabaseQuery::initDivision(function ($code, $n) use($output, $noProgress) {
         switch ($code) {
             case 0:
                 $output->writeln("<info>generate divisions table:</info>");
                 if (!$noProgress) {
                     $this->progress = new ProgressBar($output, $n);
                     $this->progress->start();
                 }
                 break;
             case 1:
                 if (!$noProgress) {
                     $this->progress->setProgress($n);
                 }
                 break;
             case 2:
                 if (!$noProgress) {
                     $this->progress->finish();
                 }
                 $output->writeln('<info> completed!</info>');
                 break;
         }
     }, true);
 }
Пример #7
0
 /**
  *
  */
 private function cleanDivision()
 {
     $this->stdout("clean divisions:", Console::FG_GREEN);
     DatabaseQuery::cleanDivision();
     $this->stdout(" completed!\n", Console::FG_GREEN);
 }