testing.PerformanceTimer Extends
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).

Inheritance

Constructor

goog.testing.PerformanceTimer(opt_numSamplesopt_timeoutInterval)

Parameters

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).

Instance Methods

Public Protected Private
finishTask_() !Object
Finishes the run of a task by creating a result object from samples, in the format described in run.
Returns: !Object  Object containing performance stats.
code »
getNumSamples() number
No description.
Returns: number  The number of times the test function will be run.
code »
getTimeoutInterval() number
No description.
Returns: number  The number of milliseconds after which the test times out.
code »
handleOptionalDeferred_(deferredFactorycontinuationFunction)
Execute a function that optionally returns a deferred object and continue with the given continuation function only once the deferred object has a result.
Arguments:
deferredFactory : goog.testing.PerformanceTimer.TestFunction
The function that optionally returns a deferred object.
continuationFunction : function()
The function that should be called after the optional deferred has a result.
code »
isDiscardOutliers() boolean
No description.
Returns: boolean  Whether outlier values are discarded prior to computing stats.
code »
run(testFn) !Object
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)
  }
Arguments:
testFn : Function
Test function whose performance is to be measured.
Returns: !Object  Object containing performance stats.
code »
runAsyncTask(task) !goog.async.Deferred
Executes the test function of the specified task asynchronously. The test function is expected to take a callback as input and has to call it to signal that it's done. In addition, if specified, the setUp and tearDown functions of the task are invoked before and after each invocation of the test function. Note that setUp/tearDown functions take a callback as input and must call this callback when they are done.
Arguments:
task : goog.testing.PerformanceTimer.Task
A task describing the test function to invoke.
Returns: !goog.async.Deferred  The deferred result, eventually an object containing performance stats.
code »
runAsyncTaskSample_(testFnsetUpFntearDownFnresultsamplestestStart)
Runs a task once, waits for the test function to complete asynchronously and starts another run if not enough samples have been collected. Otherwise finishes this task.
Arguments:
testFn : goog.testing.PerformanceTimer.TestFunction
The test function.
setUpFn : goog.testing.PerformanceTimer.TestFunction
The set up function that will be called once before the test function is run.
tearDownFn : goog.testing.PerformanceTimer.TestFunction
The set up function that will be called once after the test function completed.
result : !goog.async.Deferred
The deferred result, eventually an object containing performance stats.
samples : !Array.<number>
The time samples from all runs of the test function so far.
testStart : number
The timestamp when the first sample was started.
code »
runTask(task) !Object
Executes the test function of the specified task as described in 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.
Arguments:
task : goog.testing.PerformanceTimer.Task
A task describing the test function to invoke.
Returns: !Object  Object containing performance stats.
code »
setDiscardOutliers(discard)
Sets whether to ignore the smallest and the largest values when computing stats.
Arguments:
discard : boolean
Whether to discard outlier values.
code »
setNumSamples(numSamples)
Sets the number of times the test function will be run.
Arguments:
numSamples : number
Number of times to run the test function.
code »
setTimeoutInterval(timeoutInterval)
Sets the number of milliseconds after which the test times out.
Arguments:
timeoutInterval : number
Timeout interval in ms.
code »

Instance Properties

discardOutliers_ :
Whether to discard outliers (i.e. the smallest and the largest values) from the sample set before computing statistics. Defaults to false.
Code »
numSamples_ :
Number of times the test function is to be run; defaults to 10.
Code »
timeoutInterval_ :
Number of milliseconds after which the test is to be aborted; defaults to 5,000ms.
Code »

Static Methods

goog.testing.PerformanceTimer.createResults(samples) !Object
Creates a performance timer results object by analyzing a given array of sample timings.
Arguments:
samples : Array.<number>
The samples to analyze.
Returns: !Object  Object containing performance stats.
code »

Static Properties

goog.testing.PerformanceTimer.TestFunction :
A test function whose performance should be measured or a setUp/tearDown function. It may optionally return a deferred object. If it does so, the test harness will assume the function is asynchronous and it must signal that it's done by setting an (empty) result on the deferred object. If the function doesn't return anything, the test harness will assume it's synchronous.
Code »

Package testing

Package Reference