# data-generators-benchmark

> Benchmark for generation data libraries

Latest version **2.1.3** (published 2024-05-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install data-generators-benchmark
pnpm add data-generators-benchmark
yarn add data-generators-benchmark
bun add data-generators-benchmark
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.3 |
| Published | 2024-05-31 |
| First published | 2023-12-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 15.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Boris Prokhorov |
| Maintainers | lixonik |
| Keywords | benchmark, data_generation, testing, frontend, performance, Node.js |

## Links

- npm: https://www.npmjs.com/package/data-generators-benchmark
- Repository: https://github.com/Lixonik/data-generators-benchmark
- Homepage: https://github.com/Lixonik/data-generators-benchmark#readme
- Issues: https://github.com/Lixonik/data-generators-benchmark/issues
- npm.io page: https://npm.io/package/data-generators-benchmark

## Dependencies (3)

- [canvas](https://npm.io/package/canvas.md) ^2.11.2
- [chart.js](https://npm.io/package/chart.js.md) ^3.9.1
- [chartjs-node-canvas](https://npm.io/package/chartjs-node-canvas.md) ^4.1.6

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 2.1.3 (latest) — 2024-05-31
- 2.1.2 — 2024-05-08
- 2.1.1 — 2024-04-22
- 2.1.0 — 2024-04-19
- 2.0.0 — 2024-04-19
- 1.0.0 — 2023-12-25

## README

# data-generators-benchmark
## A robust benchmarking library that supports high-resolution timers & returns statistically significant results.

### Documentation
The `Benchmark` class provides a means for benchmarking data generation functions. It measures the execution time of functions for various input data, plots generation time versus string length, and stores the results in images.

The functionality of the class is implemented using the following static methods available to the user:
1. `pushCandidate(...candidates: Function[]): void` -- method for adding candidate functions to the array of generator functions. Generator functions represent functions whose execution time will be measured and analyzed.
2. `removeCandidate(...candidates: Function[]): void` -- method for removing candidates functions from the array of generator functions.
3. `clearCandidate(): void` -- method for clearing all candidate functions from the array of generator functions.
4. `plotAndSaveMeasurementTimesCharts(pathToMeasurementsPng?: PathLike): void` -- the method builds and saves graphs of generation time versus string length for all added generator functions. The results are saved as PNG images. The path for saving images can be specified with the optional parameter `pathToMeasurementsPng`. If the path is not specified, the images are saved in the './measurements' directory.
5. `printAvgGenerationTimes(precision?: number): void` - the method prints to the console the average generation time for each generator function. The `precision` parameter is optional and specifies the number of decimal places to display the time in milliseconds. If `precision` is not specified, the full time value is printed.
6. `printPerformanceLevels(): void` - the method prints the performance level for each generator function to the console. The performance level is determined by comparing the average generation time with the minimum value among all generator functions. The "high" level is assigned to functions whose average generation time is equal to the minimum, the "middle" level is assigned to functions whose ratio of the minimum time to the function generation time is in the range from 1 to 2, the "low" level is assigned to functions for which this ratio is significant greater than or equal to 2.

### Installation
Via npm:
```shell
npm i --save data-generators-benchmark
```
In Node.js:
```ts
import Benchmark from 'data-generators-benchmark'
```

Usage example:
```ts
import { faker } from '@faker-js/faker'
import Benchmark from '../src/index'
import { randomString } from 'zufall'

const fakerGeneratorString = (arg: number) => faker.string.alpha(arg)

const zufallGeneratorString = (arg: number) => randomString(arg)

// Pushing generator functions to the benchmark
Benchmark.pushCandidate(fakerGeneratorString)
Benchmark.pushCandidate(zufallGeneratorString)
    
// Plotting performance charts
Benchmark.plotAndSaveMeasurementTimesCharts()

// Output of average generation time with a precision of two decimal places
Benchmark.printAvgGenerationTimes(2)
    
// // Output of perfomance levels for generator functions
Benchmark.printPerformanceLevels()
```

---
_Source: https://npm.io/package/data-generators-benchmark · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
