This is an example showing performance differences between Blocking Code, Async Programming and Web Workers.

Problem Statement : Calculate average of sum of given count of numbers.

Default count is different for each case, but you can change and try yourself
Try giving 100000000 value in Blocking code and web workers input box and then try to interact with the page after clicking on calculate average.


Blocking Code

(Using for loop to calculate)

Time Taken :

Average :


Async (timeout)

(Using recursion and setTimeout)

Time Taken :

Average :



With Web Worker

(for loop logic moved to web worker)

Time Taken :

Average :


You can read more about web workers here