ExecutorsΒΆ
An executor is responsible for executing your benchmarks. It accepts an
ExecutionContext
and returns ExecutionResults
.
PHPBench comes with two executor variations:
The remote executor executes you benchmarks in a separate process using a generated template.
The local executor executes you benchmarks the same process (sharing the runtime environment of PHPBench).
This executor will return a constant configured value for each iteration.
namespace PhpBench\Examples\Extension\Executor;
use PhpBench\Executor\BenchmarkExecutorInterface;
use PhpBench\Executor\ExecutionContext;
use PhpBench\Executor\ExecutionResults;
use PhpBench\Model\Result\TimeResult;
use PhpBench\Registry\Config;
use Symfony\Component\OptionsResolver\OptionsResolver;
class AcmeExecutor implements BenchmarkExecutorInterface
{
private const CONFIG_MICROSECONDS = 'microseconds';
public function configure(OptionsResolver $options): void
{
$options->setDefaults([
self::CONFIG_MICROSECONDS => 5
]);
}
public function execute(ExecutionContext $context, Config $config): ExecutionResults
{
return ExecutionResults::fromResults(
new TimeResult($config[self::CONFIG_MICROSECONDS])
);
}
}
You can register it in your extension as follows:
class AcmeExtension implements ExtensionInterface
{
public function configure(OptionsResolver $resolver): void
{
}
public function load(Container $container): void
{
$container->register(AcmeExecutor::class, function (Container $container) {
return new AcmeExecutor();
}, [
RunnerExtension::TAG_EXECUTOR => [
'name' => 'acme',
]
]);
}
}