Is there any way to check/compare JavaScript codes' performances on my pc/browser?
Like,
Method 1:
var x = 3; if (x === 1) { console.log(1); } else { console.log(2); } Method 2:
var x = 3; switch (a) { case 1: console.log(1); break; default: console.log(2); } Here, 'Method 1' and 'Method 2' both does the same thing, and if I search on the internet there might be several benchmarks to prove which method is faster/efficient.
But I want to check it myself (offline methods, i mean on my pc would be better for me).
Thanks :)
switchandif/else if/elseare effectively the same thing in JavaScript. I'd expect your two code examples above, if they were identified as performance-critical, to end up being compiled to the same machine code by Chrome's V8 engine, for instance.