DEV Community

imsabir
imsabir

Posted on

3 3

Weird JavaScript - Part 2 ๐Ÿง‘โ€๐Ÿ’ป

Heyy!! I am JavaScript ๐Ÿ‘‹.
Instead Weird Javascript!!
I am back with new chapter, a new weridness.


Programming is usually taught by Examples!
- Niklaus Wirth (creator of the **PASCAL **Language)


Normally, we use to follow the principle technique of development as

๐Ÿ‘‰ Wireframing
๐Ÿ‘‰ UI/UX Design
๐Ÿ‘‰ HTML / CSS Development
๐Ÿ‘‰ JS with Test case Developement
๐Ÿ‘‰ All Good -> We are good to deliver โœ”๏ธ .

๐Ÿคช Not exactly same but something like this.


After 2 days: page taking long time to load.

OMG!๐Ÿ˜จ๐Ÿ˜จ What happened?
Till yesterday everything was okay.๐Ÿ˜จ๐Ÿ˜ฏ

Jhon investigating that and he found there are 2 functions in code and one of the function taking long time to execute.
โ“โ“โ“
But he also struckโ“โ“
How to find which function is taking long time to execute?


Here is JavaScript for your help
๐Ÿ’ก๐Ÿ’ก๐Ÿ’ก๐Ÿ’ก๐Ÿ’ก ๐Ÿ’ฏ๐Ÿ’ฏ๐Ÿ’ฏ๐Ÿ’ฏ
According MDN Web Docs there is console.time(),console.timeLog() and console.timeEnd() methods.
Step:

  1. Start the timer by writing console.time('some-label') with some label.
  2. console.timeLog('label for start timer') will logs the current value of timer.
  3. console.timeEnd('label for stop timer') will stop the timer and logs the time particular execution runs.

Just implement like below and get your leaky function. Cheers!!
๐Ÿ’ฏ๐Ÿ’ฏ๐Ÿ’ฏ

console.time("answer time");
// answer timer
alert("Click to continue");
console.timeLog("answer time");
alert("Do a bunch of other stuff...");
console.timeEnd("answer time");
Enter fullscreen mode Exit fullscreen mode

This way Jhon can check the which function taking how much time for executing the respective task and Jhon resolved the issue.


Ongoing quiz: can you solve this javascript basic (part 1 of this series)


Don't forget to follow @msabir for more such Weird JavaScript and understanding its under the hood concepts.

Till then take care.

Top comments (1)

Collapse
 
msabir profile image
imsabir โ€ข

Stay tune for more such updates

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

๐Ÿ‘‹ Kindness is contagious

Please leave a โค๏ธ or a friendly comment on this post if you found it helpful!

Okay