# isomorphic-benchmark

> Benchmark stuff with javascript either in node or browser

Latest version **1.0.16** (published 2016-10-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install isomorphic-benchmark
pnpm add isomorphic-benchmark
yarn add isomorphic-benchmark
bun add isomorphic-benchmark
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.16 |
| Published | 2016-10-03 |
| First published | 2016-10-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Marco Guaspari Worms |
| Maintainers | worms |

## Links

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

## Recent versions

- 1.0.16 (latest) — 2016-10-03
- 1.0.15 — 2016-10-03
- 1.0.14 — 2016-10-03
- 1.0.12 — 2016-10-03
- 1.0.11 — 2016-10-03
- 1.0.10 — 2016-10-03
- 1.0.9 — 2016-10-03
- 1.0.8 — 2016-10-02
- 1.0.7 — 2016-10-02
- 1.0.6 — 2016-10-02
- 1.0.5 — 2016-10-02
- 1.0.4 — 2016-10-02
- 1.0.3 — 2016-10-02
- 1.0.2 — 2016-10-02
- 1.0.1 — 2016-10-02
- … 1 more at https://npm.io/package/isomorphic-benchmark/versions

## README

[![Build Status](https://travis-ci.org/MarcoWorms/isomorphic-benchmark.svg?branch=master)](https://travis-ci.org/MarcoWorms/isomorphic-benchmark)

`npm install isomorphic-benchmark --save`

Node
```javascript
const runBenchmark = require('isomorphic-benchmark')
```

Browser (adds a global "runBenchmark")
```javascript
<script src="./dist/benchmark.js"></script>
```

Example test
```javascript
const aBenchmark = {
  description: 'sum',
  iterations: 10,
  tests: [
    {
      description: 'sugar',
      amount: 100000,
      testFunc: () => {
        var a
        a += 1
      }
    },
    {
      description: 'nosugar',
      amount: 100000,
      testFunc: () => {
        var a
        a = a + 1
      }
    },
  ]
}
```

Example result handling in node:
```javascript
const results = runBenchmark(aBenchmark)

var fs = require('fs');
var outputFilename = './' + results.description + '.json';

fs.writeFile(outputFilename, JSON.stringify(results, null, 4), function(err) {
  if(err) {
    console.log(err);
  } else {
    console.log("JSON saved to " + outputFilename);
  }
});
```

Example result handling in browser:
```javascript
const results = runBenchmark(aBenchmark)
console.log(JSON.stringify(results, null, 4))
```

or displayed as tabular data using [console.table](https://developer.mozilla.org/en-US/docs/Web/API/Console/table)
```javascript
const results = runBenchmark(aBenchmark);
results.iterations.forEach(console.table)
```

Full example:
```javascript
const aBenchmark = {
  description: 'sum',
  iterations: iterationAmount,
  tests: [
    {
      description: 'sugar',
      amount: 100000,
      testFunc: (persist) => {
        persist.test.foo += 1
        persist.iteration.bar += 1
      }
    },
    {
      description: 'nosugar',
      amount: 100000,
      testFunc: (persist) => {
        persist.test.foo = persist.test.foo + 1
        persist.iteration.bar = persist.iteration.bar + 1
      }
    },
  ],
  beforeEachTestFunc: (persist) => {
    // you can add stuff to persist other than test or iteration that will persist the whole benchmark.
    persist.myVar = 1
  },
  persistTest: () => {
    return {
      foo: 0
    }
  },
  persistIteration: () => {
    return {
      bar: 0
    }
  }
}
```

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