An Easy Way To Measure Performance In JavaScript/TypeScript

An Easy Way To Measure Performance In JavaScript/TypeScript

A quick and easy way to measure the performance of your method in JavaScript and TypeScript.

A quick and easy way to measure the performance of your method in JavaScript and TypeScript.

Image for post

Photo by  Dawid Małecki on  Unsplash

Performance Measurement in JavaScript

Measuring the performance of a certain method in JavaScript or any other language is actually pretty simple and generally can be split up into 4 parts.

  • Get the current time = Start time
  • Run the method code
  • Get the current time = End time
  • Subtract the end time from the start time = Run duration of your method

So what you would do in your JavaScript is shown in the next snippet:

const myMethod = () => {
    const startTimeInMs = new Date().getTime();

    // Do some heavy computation
    // ..........
    // ////////////////////////////////////////

    const endTimeInMs = new Date().getTime();
    const durationInMs = endTimeInMs - startTimeInMs;

    console.log(`myMethod took ${durationInMs} ms`);
};

programming typescript javascript

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Object-Oriented Programming with Javascript — using Typescript

Object-Oriented Programming With JavaScript — Using Typescript. TypeScript lets you write JavaScript the way you really want to. TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. TypeScript is pure Object-oriented with classes, interfaces, and statically typed like C# or Java.

What is TypeScript? Why TypeScript? and Why Not TypeScript?

TypeScript extends JavaScript by adding Types. There are many great reasons to switch to TypeScript. Especially if your team uses JavaScript. There are some reasons to not use TypeScript as there are with any language or framework.

TypeScript Tutorial For JavaScript Developers - TypeScript Basics

TypeScript Tutorial For JavaScript Developers - TypeScript Basics. I will show you guys 4 example of JavaScript code, and how to convert it to TypeScript. This is a typescript beginners tutorial.

TypeScript: A Superset of JavaScript

Multi-paradigm, Functional, Generic, Imperative, Object-Oriented. In this article, I have shared the essential information about TypeScript programming language. This article contains a basic overview, brief history, features and applications of TypeScript. TypeScript is getting more popular in Full-stack development. In terms of popularity, in the last two years TypeScript pulled ahead of Ruby, Shell, and C.

How an Anti-TypeScript “JavaScript Developer” Like Me Became a TypeScript Fan

In this article, I will discuss my journey from being an anti-TypeScript developer to a developer who now couldn’t think of going back to the plain JavaScript world. Let's see How an Anti-TypeScript “JavaScript Developer” Like Me Became a TypeScript Fan.