Comparing version 3.3.0 to 3.3.1
@@ -10,3 +10,3 @@ { | ||
], | ||
"version": "3.3.0", | ||
"version": "3.3.1", | ||
"author": "Joel Edwards (https://github.com/joeledwards)", | ||
@@ -13,0 +13,0 @@ "contributors": [ |
@@ -0,38 +1,57 @@ | ||
# durations | ||
Stopwatch | ||
=========== | ||
## Compatibilty | ||
A nanosecond granularity (on Node.js) stopwatch with chainable control methods, | ||
and built-in formatting. | ||
Both Node.js and browsers are supported by `durations`. When using Node.js, the nanosecond-granulatiry `process.hrtime()` function is used. The best substitution is selected when in the browser such that consistency is maintained even if time granularity cannot be. | ||
Timer | ||
===== | ||
## Installation | ||
Times the execution of a function, and returns the duration. | ||
```shell | ||
npm install --save durations | ||
``` | ||
Duration | ||
======== | ||
## Methods | ||
The following functions are exported: | ||
* `duration(nanoseconds)` - constructs a new Duration | ||
* `nanos(nanoseconds)` - constructs a new Duration | ||
* `micros(microseconds)` - constructs a new Duration | ||
* `millis(milliseconds)` - constructs a new Duration | ||
* `seconds(seconds)` - constructs a new Duration | ||
* `stopwatch()` - constructs a new Stopwatch (stopped) | ||
* `time(function)` - times a function | ||
* `timeAsync(function(callback))` - times a function asynchronously | ||
## Duration | ||
Represents a duration with nanosecond granularity, and provides methods | ||
for converting to other granularities, and formatting the duration. | ||
Installation | ||
============ | ||
```bash | ||
npm install --save durations | ||
``` | ||
Usage | ||
===== | ||
```coffeescript | ||
{duration, stopwatch, time: timeSync, timeAsync} = require 'durations' | ||
{duration} = require 'durations' | ||
nanoseconds = 987654321 | ||
console.log "Duration is", duration(nanoseconds).format() | ||
``` | ||
### Methods | ||
* `format()` - human readable string representing the duration | ||
* `nanos()` - duration as nanoseconds | ||
* `micros()` - duration as microseconds | ||
* `millis()` - duration as milliseconds | ||
* `seconds()` - duration as seconds | ||
* `minutes()` - duration as minutes | ||
* `hours()` - duration as hours | ||
* `days()` - duration as days | ||
# Or, since toString() is an alias to format() | ||
console.log "Duration is #{duration(nanoseconds)}" | ||
## Stopwatch | ||
A nanosecond granularity (on Node.js) stopwatch with chainable control methods, | ||
and built-in formatting. | ||
```coffeescript | ||
{stopwatch} = require 'durations' | ||
watch = stopwatch() | ||
@@ -43,3 +62,18 @@ watch.stop() # Pauses the stopwatch. Returns the stopwatch. | ||
duration = watch.duration() # Returns the Duration. | ||
``` | ||
### Methods | ||
* `start()` - start the stopwatch (no-op if already running) | ||
* `stop()` - stop the stopwatch (no-op if not running) | ||
* `reset()` - reset the stopwatch to zero elapsed time (implies stop) | ||
* `duration()` - fetch the elapsed time as a Duration | ||
* `isRunning()` - is the stopwatch running (`true`/`false`) | ||
## Timer | ||
Times the execution of a function, and returns the duration. | ||
```coffeescript | ||
{time: timeSync, timeAsync} = require 'durations' | ||
# Synchronous work | ||
@@ -63,6 +97,1 @@ someFunction = -> | ||
Compatibilty | ||
============ | ||
The `durations` module supports both Node.js and browsers. When using Node.js, the nanosecond-granulatiry `process.hrtime()` function is used. The best substitution is selected when in the browser such that consistency is maintained even if time granularity cannot be. | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14021
96