Skip to content

Commit

Permalink
Merge pull request #3 from thomaschaplin/master
Browse files Browse the repository at this point in the history
feat(verifyMeasurement): add marginOfErrorUnder & standardDeviationUnder
  • Loading branch information
mtkennerly authored Feb 5, 2021
2 parents 6476504 + b05e99b commit 12396d6
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ export interface MeasureOptions {
*/
maxUnder?: number;

/**
* If the margin of error at 95% confidence level duration exceeds this many milliseconds,
* throw a [[PerformanceError]].
*/
marginOfErrorUnder?: number;

/**
* If the standard deviation of all durations measured exceeds this many milliseconds,
* throw a [[PerformanceError]].
*/
standardDeviationUnder?: number;

/**
* Callback to invoke before each iteration.
*/
Expand Down Expand Up @@ -228,6 +240,16 @@ function verifyMeasurement(measurement: Measurement, options: MeasureOptions): v
throw new PerformanceError(`Maximum time of ${measurement.max} ms exceeded threshold of ${options.maxUnder} ms`);
}
}
if (options.marginOfErrorUnder !== undefined) {
if (measurement.marginOfError > options.marginOfErrorUnder) {
throw new PerformanceError(`Margin of error time of ${measurement.marginOfError} ms exceeded threshold of ${options.marginOfErrorUnder} ms`);
}
}
if (options.standardDeviationUnder !== undefined) {
if (measurement.standardDeviation > options.standardDeviationUnder) {
throw new PerformanceError(`Standard deviation time of ${measurement.standardDeviation} ms exceeded threshold of ${options.standardDeviationUnder} ms`);
}
}
}

/**
Expand Down

0 comments on commit 12396d6

Please sign in to comment.