Skip to content
tsdotnetPublic

About

A stopwatch class with lap timing and easy to use static methods. Useful for diagnostics.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

@tsdotnet/stopwatch: Time it, lap by lap. A small stopwatch for diagnostics.

npm version GitHub license

Stopwatch times code with start, stop, lap and reset, like .NET's Stopwatch.

Install

npm install @tsdotnet/stopwatch

Usage

import Stopwatch from '@tsdotnet/stopwatch';

const watch = Stopwatch.startNew();
doWork();
watch.stop();
watch.elapsedMilliseconds; // e.g. 250

const time = Stopwatch.measure(() => doWork()); // a TimeSpan

Stop and start() again to resume; lap() returns the time since the last lap, and reset() clears it.

Use it from

ESM (import Stopwatch from '@tsdotnet/stopwatch';) or CommonJS (const Stopwatch = require('@tsdotnet/stopwatch').default;).

In a browser, without a bundler
<script src="https://cdn.jsdelivr.net/npm/@tsdotnet/type@1/dist/umd/type.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tsdotnet/compare@1/dist/umd/compare.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tsdotnet/exceptions@1/dist/umd/exceptions.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tsdotnet/disposable@2/dist/umd/disposable.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tsdotnet/lazy@2/dist/umd/lazy.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tsdotnet/date-time@2/dist/umd/date-time.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tsdotnet/stopwatch@2/dist/umd/stopwatch.min.js"></script>
<script>
  const Stopwatch = tsdotnet.stopwatch.default;
</script>

Docs

tsdotnet.github.io/stopwatch

About

A stopwatch class with lap timing and easy to use static methods. Useful for diagnostics.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages