private function buildBenchmarkMetadata(BenchmarkMetadata $classMetadata, ReflectionHierarchy $hierarchy)
 {
     $annotations = array();
     $reflectionHierarchy = array_reverse(iterator_to_array($hierarchy));
     foreach ($reflectionHierarchy as $reflection) {
         $benchAnnotations = $this->docParser->parse($reflection->comment, sprintf('benchmark %s', $reflection->class));
         $annotations = array_merge($annotations, $benchAnnotations);
         foreach ($benchAnnotations as $annotation) {
             if ($annotation instanceof BeforeClassMethods) {
                 $classMetadata->setBeforeClassMethods($annotation->getMethods());
             }
             if ($annotation instanceof AfterClassMethods) {
                 $classMetadata->setAfterClassMethods($annotation->getMethods());
             }
             $this->processAbstractMetadata($classMetadata, $annotation);
         }
     }
     foreach ($reflectionHierarchy as $reflection) {
         foreach ($reflection->methods as $reflectionMethod) {
             if ('bench' !== substr($reflectionMethod->name, 0, 5)) {
                 continue;
             }
             $subjectMetadata = $classMetadata->getOrCreateSubjectMetadata($reflectionMethod->name);
             // apply the benchmark annotations to the subject
             foreach ($annotations as $annotation) {
                 $this->processAbstractMetadata($subjectMetadata, $annotation);
             }
             $this->buildSubjectMetadata($subjectMetadata, $reflectionMethod);
             $classMetadata->setSubjectMetadata($subjectMetadata);
         }
     }
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function benchmarkStart(BenchmarkMetadata $benchmark)
 {
     static $first = true;
     if (false === $first) {
         $this->output->write(PHP_EOL);
     }
     $first = false;
     $this->output->writeln(sprintf('<comment>%s</comment>', $benchmark->getClass()));
     $this->output->write(PHP_EOL);
 }
Beispiel #3
0
 public function benchmarkStart(BenchmarkMetadata $benchmark)
 {
     static $first = true;
     if ($this->showBench) {
         // do not output a line break on the first run
         if (false === $first) {
             $this->output->writeln('');
         }
         $first = false;
         $this->output->writeln($benchmark->getClass());
     }
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  */
 public function benchmarkStart(BenchmarkMetadata $benchmark)
 {
     static $first = true;
     if (false === $first) {
         $this->output->write(PHP_EOL);
     }
     $first = false;
     $this->output->write(sprintf('<comment>%s</comment>', $benchmark->getClass()));
     $subjectNames = array();
     foreach ($benchmark->getSubjectMetadatas() as $subject) {
         $subjectNames[] = sprintf('#%s %s', $subject->getIndex(), $subject->getName());
     }
     $this->output->write(sprintf(' (%s)', implode(', ', $subjectNames)));
     $this->output->write(PHP_EOL);
     $this->output->write(PHP_EOL);
 }
Beispiel #5
0
 private function runBenchmark(RunnerContext $context, BenchmarkMetadata $benchmark, \DOMElement $benchmarkEl)
 {
     if ($benchmark->getBeforeClassMethods()) {
         $this->executor->executeMethods($benchmark, $benchmark->getBeforeClassMethods());
     }
     foreach ($benchmark->getSubjectMetadatas() as $subject) {
         $subjectEl = $benchmarkEl->appendElement('subject');
         $subjectEl->setAttribute('name', $subject->getName());
         if (true === $subject->getSkip()) {
             continue;
         }
         foreach ($subject->getGroups() as $group) {
             $groupEl = $subjectEl->appendElement('group');
             $groupEl->setAttribute('name', $group);
         }
         $this->logger->subjectStart($subject);
         $this->runSubject($context, $subject, $subjectEl);
         $this->logger->subjectEnd($subject);
     }
     if ($benchmark->getAfterClassMethods()) {
         $this->executor->executeMethods($benchmark, $benchmark->getAfterClassMethods());
     }
 }
Beispiel #6
0
 /**
  * {@inheritdoc}
  */
 public function benchmarkStart(BenchmarkMetadata $benchmark)
 {
     $this->output->writeln(sprintf('<comment>%s</comment>', $benchmark->getClass()));
     $this->output->write(PHP_EOL);
 }
Beispiel #7
0
 /**
  * {@inheritdoc}
  */
 public function executeMethods(BenchmarkMetadata $benchmark, array $methods)
 {
     $tokens = array('class' => $benchmark->getClass(), 'file' => $benchmark->getPath(), 'methods' => var_export($methods, true));
     $payload = $this->launcher->payload(__DIR__ . '/template/benchmark_static_methods.template', $tokens);
     $payload->launch();
 }
 public function processBenchmark(BenchmarkMetadata $benchmark, $annotation)
 {
     if ($annotation instanceof BeforeClassMethods) {
         $benchmark->setBeforeClassMethods($annotation->getMethods());
     }
     if ($annotation instanceof AfterClassMethods) {
         $benchmark->setAfterClassMethods($annotation->getMethods());
     }
 }
Beispiel #9
0
 private function runBenchmark(ExecutorInterface $executor, RunnerContext $context, Benchmark $benchmark, BenchmarkMetadata $benchmarkMetadata)
 {
     if ($benchmarkMetadata->getBeforeClassMethods()) {
         $executor->executeMethods($benchmarkMetadata, $benchmarkMetadata->getBeforeClassMethods());
     }
     // the keys are subject names, convert them to numerical indexes.
     $subjectMetadatas = array_filter($benchmarkMetadata->getSubjects(), function ($subjectMetadata) {
         if ($subjectMetadata->getSkip()) {
             return false;
         }
         return true;
     });
     $subjectMetadatas = array_values($subjectMetadatas);
     foreach ($subjectMetadatas as $subjectMetadata) {
         // override parameters
         $subjectMetadata->setIterations($context->getIterations($subjectMetadata->getIterations()));
         $subjectMetadata->setRevs($context->getRevolutions($subjectMetadata->getRevs()));
         $subjectMetadata->setWarmup($context->getWarmup($subjectMetadata->getWarmUp()));
         $subjectMetadata->setSleep($context->getSleep($subjectMetadata->getSleep()));
         $subjectMetadata->setRetryThreshold($context->getRetryThreshold($this->retryThreshold));
         $benchmark->createSubjectFromMetadata($subjectMetadata);
     }
     $this->logger->benchmarkStart($benchmark);
     foreach ($benchmark->getSubjects() as $index => $subject) {
         $subjectMetadata = $subjectMetadatas[$index];
         $this->logger->subjectStart($subject);
         $this->runSubject($executor, $context, $subject, $subjectMetadata);
         $this->logger->subjectEnd($subject);
     }
     $this->logger->benchmarkEnd($benchmark);
     if ($benchmarkMetadata->getAfterClassMethods()) {
         $executor->executeMethods($benchmarkMetadata, $benchmarkMetadata->getAfterClassMethods());
     }
 }