This simple class can be used to measure performance of certain JavaScript code.
-
Enable Node module export
module.exports = Probe;in Probe.jsDo not forget to disable browser import, native ES5 export in Probe.js
-
Import Probe into your application.
For example:
const Probe = require('./Probe.js');
-
Enable Browser module export
export {Probe};in Probe.jsDo not forget to disable Node import, native ES5 export in Probe.js
-
Import Probe into your application.
For example:
import {Probe} from './Probe.js';
Click the link to open index.js to view how the code works.
Probe(label) Label is type String.
labelstartTimestopTimeelapsedTime
startTimer()stopTimer()
-
Instantiate Probe class.
For example:
let myProbe = new Probe('measureRead');You can get the probe label by
myProbe.label.Probe is created as an instantiable class to enable multiple probes running at the same time.
-
Start probe timer
For example:
myProbe.startTimer();You can get start time by
myProbe.startTime. -
Stop probe timer
For example:
myProbe.stopTimer();You can get stop time by
myProbe.startTimeand elapsed time bymyProbe.elapsedTime
Running the code in Node and Browser is the same. The example index.js works on Node.
Type node index.js in the same folder from terminal to run the example.
Return to Index