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


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