19

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?

asked Jun 27, 2013 at 9:17

4 Answers 4

51

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);
answered Jun 27, 2013 at 9:22
Sign up to request clarification or add additional context in comments.

1 Comment

window.performance.now() should be used instead of new Date()stackoverflow.com/a/21121773/1131963
8

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

answered Oct 12, 2014 at 19:36

Comments

1

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. :)

answered Jun 24, 2020 at 12:09

Comments

0
var startTime = Date.now();
// code ...
console.log("Elapsed time (ms): " + (Date.now() - startTime));
answered Mar 1, 2016 at 7:50

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.