JSPM

stopwatch-node

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 8910
  • Score
    100M100P100Q120751F
  • License MIT

stopwatch for nodejs inspired by Spring Stopwatch

Package Exports

  • stopwatch-node

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (stopwatch-node) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Stopwatch

A simple JS/TS Stopwatch with 0 dependency.

This is inspired by the Spring-Stopwatch. Written in Typescript, 100%` Test Coverage.

Install

npm install stopwatch-node

Example

import { StopWatch } from 'stopwatch-node';

const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));

(async () => {
  const sw = new StopWatch('sw');
  sw.start('Task 1');
  await sleep(1000);
  sw.stop();
  // whether the stopwatch is currently running
  console.info(sw.isRunning());

  sw.start('Task 2');
  await sleep(1500);
  sw.stop();

  sw.start('Task 3');
  await sleep(500);
  sw.stop();

  sw.start('Task 4');
  await sleep(300);
  sw.stop();

  console.info(`Short Summary: ${sw.shortSummary()}`);
  console.info(`Task Count: ${sw.getTaskCount()}`);
  // a table describing all tasks performed
  sw.prettyPrint();
})();

Output

------------------------------------------
ms 		 % 		 Task name
------------------------------------------
1000 		 30.21 		 Task 1
1504 		 45.44 		 Task 2
505 		 15.26 		 Task 3
301 		 9.09 		 Task 4