1.0.16 • Published 8 years ago

isomorphic-benchmark v1.0.16

Weekly downloads
3
License
MIT
Repository
github
Last release
8 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

8 years ago

1.0.15

8 years ago

1.0.14

8 years ago

1.0.12

8 years ago

1.0.11

8 years ago

1.0.10

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago