Skip to content

Instantly share code, notes, and snippets.

@WebRTCGame
Created November 27, 2018 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WebRTCGame/8e7d3118e52cacbe6dbc7dd275966ad7 to your computer and use it in GitHub Desktop.
Save WebRTCGame/8e7d3118e52cacbe6dbc7dd275966ad7 to your computer and use it in GitHub Desktop.
Simple Javascript Performance Profiler Log
let perf = {
t0: 0,
t1: 0,
tick: 0,
last: 0,
start() {
this.tick = 1;
console.trace();
this.t0 = performance.now();
},
end(descriptor = "") {
let val = 0;
if (this.tick === 1) {
this.t1 = performance.now();
val = (this.t1 - this.t0);
console.table({
"Function": descriptor.toString(),
"Elapsed": val.toString(),
"Last": this.last.toString()
});
console.trace();
this.last = val;
} else {
console.log(`No perf start for ${descriptor}`);
}
this.tick = 0;
}
};
console.clear();
for (let x = 0; x < 2; x++) {
perf.start();
for (let i = 0; i < 10000; i++) {
let j = i * 10;
}
perf.end("the func");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment