The goog.testing.PerformanceTimer Class

goog.testing.PerformanceTimer(opt_numSamples, opt_timeoutInterval)

Creates a performance timer that runs test functions a number of times to generate timing samples, and provides performance statistics (minimum, maximum, average, and standard deviation).

opt_numSamples {number=}
Number of times to run the test function; defaults to 10.
opt_timeoutInterval {number=}
Number of milliseconds after which the test is to be aborted; defaults to 5 seconds (5,000ms).

The goog.testing.PerformanceTimer.Task Class

A task for the performance timer to measure. Callers can specify optional setUp and tearDown methods to control state before and after each run of the test function. … more

.createResults(samples)

Creates a performance timer results object by analyzing a given array of sample timings.

samples {Array.<number>}
The samples to analyze.
returns {Object}
Object containing performance stats.

.getNumSamples()

returns {number}
The number of times the test function will be run.

.getTimeoutInterval()

returns {number}
The number of milliseconds after which the test times out.

.isDiscardOutliers()

returns {boolean}
Whether outlier values are discarded prior to computing stats.

.run(testFn)

Executes the test function the required number of times (or until the test run exceeds the timeout interval, whichever comes first). Returns an object containing the following:

   {
     'average': average execution time (ms)
     'count': number of executions (may be fewer than expected due to timeout)
     'maximum': longest execution time (ms)
     'minimum': shortest execution time (ms)
     'standardDeviation': sample standard deviation (ms)
     'total': total execution time (ms)
   }
 
testFn {Function}
Test function whose performance is to be measured.
returns {Object}
Object containing performance stats.

.runTask(task)

Executes the test function of the specified task as described in {@code run}. In addition, if specified, the set up and tear down functions of the task are invoked before and after each invocation of the test function.

task {goog.testing.PerformanceTimer.Task}
A task describing the test function to invoke.
returns {Object}
Object containing performance stats.
@see
goog.testing.PerformanceTimer#run

.setDiscardOutliers(discard)

Sets whether to ignore the smallest and the largest values when computing stats.

discard {boolean}
Whether to discard outlier values.

.setNumSamples(numSamples)

Sets the number of times the test function will be run.

numSamples {number}
Number of times to run the test function.

.setTimeoutInterval(timeoutInterval)

Sets the number of milliseconds after which the test times out.

timeoutInterval {number}
Timeout interval in ms.