new TimePerf()
/home/remy.drouet@sglk.local/workspace/TimePerf/time-perf.js, line 48
Properties:
Example
import timePerf from "time-perf"
timePerf.start()
// ..execute algorithm to evaluate
timePerf.step("Algorithm")
// ..execute a function to evaluate
timePerf.stop("Function")
timePerf.print()
// Will display :
--------------------------------
- TimePerf result -
--------------------------------
+ Test duration : 3235 ms
+ Steps number : 2
> 1. Algorithm : 15.23 %
> 2. Function : 84.77 %
Methods
-
child(){TimePerf}
/home/remy.drouet@sglk.local/workspace/TimePerf/time-perf.js, line 331 -
Create a new TimePerf child. This child will be bind to the next step
Returns:
Type Description TimePerf child - The created child -
childStart(name){TimePerf}
/home/remy.drouet@sglk.local/workspace/TimePerf/time-perf.js, line 346 -
Create and start a new TimePerf child. This child will be bind to the next
Name Type Description name
string Child's name Returns:
Type Description TimePerf child - The created child -
childStop(name){TimePerf}
/home/remy.drouet@sglk.local/workspace/TimePerf/time-perf.js, line 355 -
Stop the last TimePerf child
Name Type Description name
string optional Name of the last child step (otherwise will be the child name) Returns:
Type Description TimePerf parent - Return the current TimePerf (not the child) -
cleanInstances()
/home/remy.drouet@sglk.local/workspace/TimePerf/time-perf.js, line 57 -
Remove all created instances
-
getTime(index){number}
/home/remy.drouet@sglk.local/workspace/TimePerf/time-perf.js, line 382 -
Return the duration (in ms) of a specific step
Name Type Description index
number Step's index Returns:
Type Description number -
lastChild(){TimePerf}
/home/remy.drouet@sglk.local/workspace/TimePerf/time-perf.js, line 369 -
Return the last created child for the current step, if none returns the current TimePerf.
Returns:
Type Description TimePerf child -
log(){TimePerf}
/home/remy.drouet@sglk.local/workspace/TimePerf/time-perf.js, line 321 -
Display the last result as a message in the console
Returns:
Type Description TimePerf -
newInstance(name){TimePerf}
/home/remy.drouet@sglk.local/workspace/TimePerf/time-perf.js, line 78 -
Create a new TimePerf instance and store it in the instance map
Name Type Description name
string Returns:
Type Description TimePerf Example
// Better use startInstance and stopInstance for simple usages // alias getInstance both will return the instance if it exists or create it if not const instance = timePerf.newInstance("instance1") if (instance.pauseStep) instance.unpause() else instance.start() // step instance.pause() // end instance.stop().print()
-
pause(){TimePerf}
/home/remy.drouet@sglk.local/workspace/TimePerf/time-perf.js, line 290 -
Switch TimePerf to pause. You can't mark a step during a pause. pause doesn't modify the previous action result and strResult
Returns:
Type Description TimePerf timePerf - The TimePerf Object Example
timePerf.step("Step name").pause().print() // Will display "[TimePerf] > 1. Step name : 127 ms"
-
print(index, silent){TimePerf}
/home/remy.drouet@sglk.local/workspace/TimePerf/time-perf.js, line 204 -
Get the result of the measurements (alias resume)
Name Type Default Description index
number optional Get only the given step result silent
boolean false optional No console message will be displayed Returns:
Type Description TimePerf timePerf - The TimePerf Object plus a percentage or an array of percentage (timePerf.result == 0 for error) Examples
// display the duration of the previous step timePerf.step("Step name").print();
// display a resume of TimePerf steps and switch to pause timePerf.stop("Last Step").print();
// display the duration of the second step timePerf.print(2);
// returns an Array of percentage without console messages timePerf.print(true);
// returns the second step percentage without console messages timePerf.print(2,true);
-
reset(){TimePerf}
/home/remy.drouet@sglk.local/workspace/TimePerf/time-perf.js, line 272 -
Resets the TimePerf tool (Removes all steps)
Returns:
Type Description TimePerf timePerf - The TimePerf Object -
start(name){TimePerf}
/home/remy.drouet@sglk.local/workspace/TimePerf/time-perf.js, line 136 -
Reset TimePerf & mark a step in TimePerf measurements associated with a given name
Name Type Description name
String Name of the new TimePerf session Returns:
Type Description TimePerf timePerf - The TimePerf Object -
startInstance(name){TimePerf}
/home/remy.drouet@sglk.local/workspace/TimePerf/time-perf.js, line 101 -
Create a new instance or get it if it exists and start/unpause it. It is recommended to use startInstance with stopInstance only
Name Type Description name
string Returns:
Type Description TimePerf Example
// At the begining of the function to measure timePerf.startInstance("Function duration") // At the end of it const endCondition = index === lastIndex timePerf.stopInstance("Function duration", endCondition)
-
step(name){TimePerf}
/home/remy.drouet@sglk.local/workspace/TimePerf/time-perf.js, line 166 -
Mark a step in TimePerf measurements associated with a given name You can also use
resume
andpause
to afterName Type Description name
string optional Name associated to the step Returns:
Type Description TimePerf timePerf - The TimePerf Object -
stop(name){TimePerf}
/home/remy.drouet@sglk.local/workspace/TimePerf/time-perf.js, line 153 -
Mark a step in TimePerf measurements associated with a given name and switch TimePerf to pause You can use
resume
just after to show a resumeName Type Description name
optional Name associated to the step Returns:
Type Description TimePerf timePerf - The TimePerf Object -
stopInstance(name, endCondition){TimePerf}
/home/remy.drouet@sglk.local/workspace/TimePerf/time-perf.js, line 120 -
Switch to pause the instance or stop, print and clean it when the endCondition is true. It is recommended to use stopInstance with startInstance only
Name Type Default Description name
string The id of the instance endCondition
boolean true optional When the instance is stopped Returns:
Type Description TimePerf -
unpause(){TimePerf}
/home/remy.drouet@sglk.local/workspace/TimePerf/time-perf.js, line 303 -
Unpauses TimePerf and returns the pause duration
Returns:
Type Description TimePerf scope - The TimePerf object plus the last pause duration Example
timePerf.unpause().log() // will display "TimePerf has marked a 20 ms pause"