Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript: measure code execution time online

I'm experiencing the need to test the performance differences of some variants of code (native/with plugins).

Is there an online service, like jsbin, jsfiddle for execution, where I can put the code in, like

// BEGIN
var bla;
jQuery.map(bla, function(){});
// END

and get execution time?

like image 507
Max Avatar asked Jun 27 '13 09:06

Max


People also ask

What is used to measure performance of JavaScript code?

measure() The measure() method creates a named timestamp in the browser's performance entry buffer between marks, the navigation start time, or the current time. When measuring between two marks, there is a start mark and end mark, respectively.


3 Answers

Using the 'User Timing API' is a modern way of doing this:
http://www.html5rocks.com/en/tutorials/webperformance/usertiming/

like image 20
Yuval A. Avatar answered Oct 02 '22 11:10

Yuval A.


One option is

jsperf.com

OR

//works in chrome and firefox
console.time("myCode"); // 'myCode' is the namespace
//execute your code here
console.timeEnd("myCode");

OR

var startTime = window.performance.now();
//execute your code here
console.log(window.performance.now() - startTime);
like image 72
Parthik Gosar Avatar answered Oct 02 '22 11:10

Parthik Gosar


Below approaches I have found till now:-

Approach 1:-

let start = window.performance.now()
/// Your code goes here
let end = window.performance.now()
console.log(`Component Persing Time: ${end - start} ms`);

Approach 2:-

let start = Date.now()
/// Your code goes here
let end = Date.now()
console.log(`Component Persing Time: ${end - start} ms`);

Approach 3:-

console.time();
// Your code goes here
console.timeEnd();

Any above approches you may proceed but got the same result. Happy coding. :)

like image 1
Mehadi Hassan Avatar answered Oct 04 '22 11:10

Mehadi Hassan