Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "utils/timeit/docs/types/index.d"

Index

Interfaces

Type aliases

Functions

Type aliases

Binary

Binary: (error: Error | null, results: Results) => void

Callback function.

param

encountered error or null

param

timing results

Type declaration

    • (error: Error | null, results: Results): void
    • Parameters

      • error: Error | null
      • results: Results

      Returns void

Callback

Callback: Nullary | Unary | Binary

Callback function.

param

encountered error or null

param

timing results

Nullary

Nullary: () => void

Callback function.

Type declaration

    • (): void
    • Returns void

Unary

Unary: (error: Error | null) => void

Callback function.

param

encountered error or null

Type declaration

    • (error: Error | null): void
    • Parameters

      • error: Error | null

      Returns void

Functions

Export assignment timeit

  • Times a snippet.

    Notes

    • The state parameter is simply an empty object which allows the before, after, and code snippets to share state.
    • Snippets always run in strict mode.
    • Always verify results. Doing so prevents the compiler from performing dead code elimination and other optimization techniques, which would render timing results meaningless.
    • Executed code is not sandboxed and has access to the global state. You are strongly advised against timing untrusted code. To time untrusted code, do so in an isolated environment (e.g., a separate process with restricted access to both global state and the host environment).
    • Wrapping asynchronous code does add overhead, but, in most cases, the overhead should be negligible compared to the execution cost of the timed snippet.
    • While many benchmark frameworks calculate various statistics over raw timing results (e.g., mean and standard deviation), do not do this. Instead, consider the fastest time an approximate lower bound for how fast an environment can execute a snippet. Slower times are more likely attributable to other processes interfering with timing accuracy rather than attributable to variability in JavaScript's speed. In which case, the minimum time is most likely the only result of interest. When considering all raw timing results, apply common sense rather than statistics.

    Parameters

    • code: string

      snippet to time

    • clbk: Callback

      callback to invoke upon completion

    Returns void

    Example

    var code = '';
    code += 'var x = Math.pow( Math.random(), 3 );';
    code += 'if ( x !== x ) {';
    code += 'throw new Error( \'Something went wrong.\' );';
    code += '}';
    
    timeit( code, done );
    
    function done( error, results ) {
        if ( error ) {
            throw error;
        }
        console.dir( results );
    }
  • Times a snippet.

    Notes

    • If the asynchronous option is set to true, the implementation assumes that before, after, and code snippets are all asynchronous. Accordingly, these snippets should invoke a next( [error] ) callback once complete. The implementation wraps the snippet within a function accepting two arguments: state and next.
    • The state parameter is simply an empty object which allows the before, after, and code snippets to share state.
    • Snippets always run in strict mode.
    • Always verify results. Doing so prevents the compiler from performing dead code elimination and other optimization techniques, which would render timing results meaningless.
    • Executed code is not sandboxed and has access to the global state. You are strongly advised against timing untrusted code. To time untrusted code, do so in an isolated environment (e.g., a separate process with restricted access to both global state and the host environment).
    • Wrapping asynchronous code does add overhead, but, in most cases, the overhead should be negligible compared to the execution cost of the timed snippet.
    • When the asynchronous option is true, ensure that the main code snippet is actually asynchronous. If a snippet releases the zalgo, an error complaining about exceeding the maximum call stack size is highly likely.
    • While many benchmark frameworks calculate various statistics over raw timing results (e.g., mean and standard deviation), do not do this. Instead, consider the fastest time an approximate lower bound for how fast an environment can execute a snippet. Slower times are more likely attributable to other processes interfering with timing accuracy rather than attributable to variability in JavaScript's speed. In which case, the minimum time is most likely the only result of interest. When considering all raw timing results, apply common sense rather than statistics.

    Parameters

    • code: string

      snippet to time

    • options: Options

      function options

    • clbk: Callback

      callback to invoke upon completion

    Returns void

    Example

    var code = 'var x = Math.pow( Math.random(), 3 );';
    code += 'if ( x !== x ) {';
    code += 'var err = new Error( \'Something went wrong.\' );';
    code += 'next( err );';
    code += '}';
    code += 'process.nextTick( next );';
    
    var opts = {
        'iterations': 1e2,
        'asynchronous': true
    };
    
    timeit( code, opts, done );
    
    function done( error, results ) {
        if ( error ) {
            throw error;
        }
        console.dir( results );
    }