Sitelet https://github.com/phpbench/phpbench/issues/304
Skip to content

Provide a way to reset state/caches at every loop #304

Description

@Ocramius

As of today's twitter thread and related example, it is currently not supported to run benchmarks and reset state at each execution of the benchmark methods.

Basically:

class MyBench
{
    public function __construct()
    {
        $this->foo = new Foo();
    }
    public function benchFoo()
    {
        $this->foo->reset(); // <- should not be included in benchmark measurement
        $this->foo->doFoo();
    }
}

A workaround (for now), is to ensure immutability by de-referencing the system under bench:

class MyBench
{
    public function __construct()
    {
        $this->foo = new Foo();
    }
    public function benchFoo()
    {
        $foo = clone $this->foo; // <- still some overhead

        $foo->doFoo();
    }
}

This needs some research, but it may be possible to have a separate resetInstance method (or such) on the benchmark, that can be measured and excluded from the output measurements.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions