Table Of Contents

Previous topic

21.35. The PostEffects Object

Next topic

21.37. The Reference Object

This Page

21.36. The Profile Object

The Profile object uses the TurbulenzEngine.time to provide a high precision timing. This can be with in a single function, e.g. timing the main loop and functions with in it, or over several frames, e.g. measuring the start up time.

The Profile object is a singleton, it does not have a create().

See Profiling JavaScript for an overview of profiling.

Required scripts

The Profile object requires:

/*{{ javascript("jslib/utilities.js") }}*/

21.36.1. Methods

21.36.1.1. start

Summary

Starts a profiling sampler with a given unique name.

Syntax

Profile.start("myFunction");
// Code to sample
Profile.stop("myFunction");

21.36.1.2. stop

Summary

Stops a profiling sampler with a given unique name. If you are profiling a function make sure all code paths that return call stop().

Syntax

Profile.start("myFunction");
// Code to sample
Profile.stop("myFunction");

21.36.1.3. reset

Summary

Resets the profiling, clearing all previous data.

Syntax

Profile.reset();

21.36.1.4. getReport

Summary

Gets a string that contains all the report data. Each line of text is data formatted with the following properties:

  • name
  • calls
  • duration
  • max
  • min
  • average
  • standard deviation
  • % of the highest duration of all profiles

Usually this will be called outside of any start/stop pair, e.g. at the end of the main loop.

Syntax

var text = Profile.getReport(sortMode, format);
sortMode
Optional. One of Profile.sortMode. The default is Profile.sortMode.duration.
format

Optional. An object specifying the format of the output with the following properties.

  • precision, defaults to 8.
  • percentagePrecision, defaults to 1.
  • separator, string that defaults to ” ” (space).

21.36.2. Properties

21.36.2.1. profiles

A dictionary of objects, keyed off the names passed in to start().

Each object has the following properties:

  • name a string, the value passed in to start().
  • calls an integer of the number of times start(name) was called.
  • duration a number of the total time, in seconds.
  • min a number of the minimum time, in seconds.
  • max a number of the maximum time, in seconds.
  • sumOfSquares the sum of the squares of duration. Used for calculating standard deviation.

Syntax

var profile = Profile.profiles["myFunction"];
var averageTime = profile.duration / profile.calls;

21.36.2.2. sortMode

An enumeration used in the getReport method.

  • alphabetical
  • duration
  • max
  • min
  • calls