Created
November 27, 2018 16:49
-
-
Save WebRTCGame/8e7d3118e52cacbe6dbc7dd275966ad7 to your computer and use it in GitHub Desktop.
Simple Javascript Performance Profiler Log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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