1.0.16 • Published 10 years ago

isomorphic-benchmark v1.0.16

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

Build Status

npm install isomorphic-benchmark --save

Node

const runBenchmark = require('isomorphic-benchmark')

Browser (adds a global "runBenchmark")

<script src="./dist/benchmark.js"></script>

Example test

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:

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:

const results = runBenchmark(aBenchmark)
console.log(JSON.stringify(results, null, 4))

Full example:

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
    }
  }
}
1.0.16

10 years ago

1.0.15

10 years ago

1.0.14

10 years ago

1.0.12

10 years ago

1.0.11

10 years ago

1.0.10

10 years ago

1.0.9

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago