feat(perf): measure error and stop automatically when the numbers are go...

...od enough.
I think it is worth extracting this `then` block into a named function to make the code easier to follow. 

Something like this:

```
var stats = calculateStatesBasedOnLogs(logs, sampleSize);
if (stats.error < maxError) {
  return stats;
} else {
  return findGoodSample(...
}
```