https://github.com/pirxpilot/akuku
Small timing counter utility.
https://github.com/pirxpilot/akuku
Last synced: 4 months ago
JSON representation
Small timing counter utility.
- Host: GitHub
- URL: https://github.com/pirxpilot/akuku
- Owner: pirxpilot
- License: isc
- Created: 2018-05-23T23:03:32.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2025-06-29T02:03:41.000Z (about 1 year ago)
- Last Synced: 2025-10-16T19:21:49.530Z (9 months ago)
- Language: JavaScript
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
- License: LICENSE
Awesome Lists containing this project
README
[![NPM version][npm-image]][npm-url]
[![Build Status][build-image]][build-url]
[![Dependency Status][deps-image]][deps-url]
# akuku
Small timing counter utility.
Uses `process.hrtime` to collect all time intervals between `start` and `stop`.
## Install
```sh
$ npm install --save akuku
```
## Usage
```js
let tm = require('akuku')('module name'); // kind of like debug
let countSomething = tm.counter('something');
tm.start();
// do something
countSomething();
tm.stop();
next = tm.start(next);
doSomethingAsync(function() {
countSomething(5); // you can optionally pass a bigger counter
next();
});
// later
tm.dump(); // will print sum of times between start and stop, and all associated counters
```
## Environment
The `AKUKU` environment variable has to be set to `1`, `on`, or `true` to enable `akuku` timers and counters.
AKUKU=1 node myapp
When `AKUKU` is not defined or set to a _falsy_ value `akuku` API is implemented using empty stubs.
## API
### `start(next = undefined, count = 1)`
Starts counting time - returns the `stop` function. If `next` is specified returns wrapped version of `next` that
stops timer before calling next.
### `stop()`
Stops counting time.
### `toString()`
Displays formatted internal state - something like:
### `toObject()`
Raw state:
- `active` - sum of all intervals between start and stop as [ seconds, nano ] pair
- `counter` - number of times start was called
- `activeNow` - true if between start and stop when called
- `counters` - additional counters as name => values object
### `counter(name)`
Creates additional named counter.
Returns counter function, which - whenever called - will increment internal counter named `name`
Its value will become part of the state.
## License
ICS © [Damian Krzeminski](https://pirxpilot.me)
[npm-image]: https://img.shields.io/npm/v/akuku
[npm-url]: https://npmjs.org/package/akuku
[build-url]: https://github.com/pirxpilot/akuku/actions/workflows/check.yaml
[build-image]: https://img.shields.io/github/actions/workflow/status/pirxpilot/akuku/check.yaml?branch=main
[deps-image]: https://img.shields.io/librariesio/release/npm/akuku
[deps-url]: https://libraries.io/npm/akuku