Skip to content

Results

Michael Best edited this page Feb 2, 2023 · 1 revision

Result instances store information about an executed callable, be it a control, or a trial. We can use a variety of methods to retrieve useful information from a result instance. Let's take a look at the methods.

Value

$result->getValue();

We can use the getValue() method to retrieve the value that was returned when the callback was executed.

Times

$result->getStartTime(); // Before execution.
$result->getEndTime();   // After execution.
$result->getTime();      // Execution duration.

The methods above allow us to examine the time efficiency of the callback. We can receive the time the callback was fired, the time it ended, and the overall duration of the callback. All values are floats, rendered from the PHP microtime(true) native function.

Memory

$result->getStartMemory(); // Memory usage before execution.
$result->getEndMemory();   // Memory usage after execution.
$result->getMemory();      // Memory usage difference.

Unfortunately, it's very difficult to determine the exact memory usage of a callback. However, by examining the memory usage before and after a callback is executed, we can determine whether a memory leak has occurred. I hope that this will be useful to some.

Exception

$result->getException();

By default, Scientist will suppress exceptions thrown by trial callbacks. We don't want our experimental code to impact our live application. If an exception was thrown during the execution of the callback, we'll receive the exception instance using the getException() method. If no exception was thrown, the value returned will be null.

Match

$result->isMatch();

The isMatch() method should only be used on trial results. The method returns a boolean value that can be used to determine whether or not the trial output matches the control output. By default, the Scientist\Matchers\StandardMatcher matcher instance will be used unless another is specified within the experiment.

Clone this wiki locally