{"_id":"56b5372e5997532100bc6c32","version":{"_id":"56b534f25f1cf00d00cc475c","project":"56b534f15f1cf00d00cc4759","__v":4,"createdAt":"2016-02-05T23:49:06.439Z","releaseDate":"2016-02-05T23:49:06.439Z","categories":["56b534f35f1cf00d00cc475d","56b55e5b5f1cf00d00cc477c","56b55e605f1cf00d00cc477d","56b5fac7e205510d001e4cfe"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"category":{"_id":"56b534f35f1cf00d00cc475d","__v":10,"project":"56b534f15f1cf00d00cc4759","version":"56b534f25f1cf00d00cc475c","pages":["56b534f45f1cf00d00cc475f","56b5368185a6922300d1c538","56b5369a168b5c1700c159a9","56b536b4eed075230097d75e","56b536c32d7fc00d0037f496","56b5370a5997532100bc6c30","56b537147bccae0d00e9a1d0","56b537252d7fc00d0037f498","56b5372e5997532100bc6c32","56b5373d7719bb190014307a"],"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-02-05T23:49:07.518Z","from_sync":false,"order":9999,"slug":"documentation","title":"Documentation"},"project":"56b534f15f1cf00d00cc4759","user":"56b534d0168b5c1700c159a7","__v":5,"githubsync":"","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-02-05T23:58:38.140Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":7,"body":"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.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Value\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n$result->getValue();\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nWe can use the `getValue()` method to retrieve the value that was returned when the callback was executed.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Times\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n$result->getStartTime(); // Before execution.\\n$result->getEndTime();   // After execution.\\n$result->getTime();      // Execution duration.\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThe 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](http://php.net/manual/en/function.microtime.php).\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Memory\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n$result->getStartMemory(); // Memory usage before execution.\\n$result->getEndMemory();   // Memory usage after execution.\\n$result->getMemory();      // Memory usage difference.\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nUnfortunately, 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.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Exception\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n$result->getException();\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nBy 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`.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Match\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n$result->isMatch();\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThe `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](doc:matchers) instance will be used unless another is specified within the [experiment](doc:experiments).","excerpt":"The result of a callable.","slug":"results","type":"basic","title":"Results"}

Results

The result of a callable.

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. [block:api-header] { "type": "basic", "title": "Value" } [/block] [block:code] { "codes": [ { "code": "<?php\n\n$result->getValue();", "language": "php" } ] } [/block] We can use the `getValue()` method to retrieve the value that was returned when the callback was executed. [block:api-header] { "type": "basic", "title": "Times" } [/block] [block:code] { "codes": [ { "code": "<?php\n\n$result->getStartTime(); // Before execution.\n$result->getEndTime(); // After execution.\n$result->getTime(); // Execution duration.", "language": "php" } ] } [/block] 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](http://php.net/manual/en/function.microtime.php). [block:api-header] { "type": "basic", "title": "Memory" } [/block] [block:code] { "codes": [ { "code": "<?php\n\n$result->getStartMemory(); // Memory usage before execution.\n$result->getEndMemory(); // Memory usage after execution.\n$result->getMemory(); // Memory usage difference.", "language": "php" } ] } [/block] 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. [block:api-header] { "type": "basic", "title": "Exception" } [/block] [block:code] { "codes": [ { "code": "<?php\n\n$result->getException();", "language": "php" } ] } [/block] 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`. [block:api-header] { "type": "basic", "title": "Match" } [/block] [block:code] { "codes": [ { "code": "<?php\n\n$result->isMatch();", "language": "php" } ] } [/block] 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](doc:matchers) instance will be used unless another is specified within the [experiment](doc:experiments).