Today I Learned - Rocky Kev

TIL Performance tests

POSTED ON:

TAGS:

While doing performance tests, I was curious how long a loop was running.

I used this trick to calculate the performance of a function.


const start = performance.now();
const end = performance.now();

const total = start - end;

console.log(`function took ${total} milliseconds to run`);

via 12 Important JavaScript Functions Every Web Developer Should Know


Related TILs

Tagged:

TIL why google recommends you avoid document.write()

By injecting it with code, it bypasses the preload scanner. This means that the browser can’t request this file until it’s actually run the '<script>' block that inserts it, which is very much just-in-time (and too late).

TIL prioritizing Javascript

... async and defer attributes should be used where possible to avoid render blocking of the DOM. Render blocking is when the browser must halt all rendering of the page in order to process a resource that the page depends on.

TIL problem with AJAX

Synchronous XHR is harmful for performance because the event loop and main thread is blocked until the request is finished, resulting in the page hanging until the data becomes available. fetch is a much more effective and efficient alternative with a simpler API, and has no support for synchronous fetching of data.