let i = 0;

let start = Date.now();

function count() {

  // القيام بجزء من المهمّة الثقيلة (*)
  do {
    i++;
  } while (i % 1e6 != 0);

  if (i == 1e9) {
    alert("Done in " + (Date.now() - start) + 'ms');
  } else {
    setTimeout(count); // برمجة الاستدعاء الجديد (**)
  }

}

count();
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.