Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nanobench

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nanobench

Simple benchmarking tool with TAP-like output that is easy to parse

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
90K
increased by2.65%
Maintainers
1
Weekly downloads
 
Created
Source

nanobench

Simple benchmarking tool with TAP-like output that is easy to parse.

npm install nanobench

Usage

var bench = require('nanobench')

bench('sha256 200.000 times', function (b) {
  var crypto = require('crypto')
  var data = new Buffer('hello world')

  b.start()

  for (var i = 0; i < 200000; i++) {
    data = crypto.createHash('sha256').update(data).digest()
  }

  b.end()
})

bench('sha1 200.000 times', function (b) {
  var crypto = require('crypto')
  var data = new Buffer('hello world')

  b.start()

  for (var i = 0; i < 200000; i++) {
    data = crypto.createHash('sha1').update(data).digest()
  }

  b.end()
})

bench('sha256 200.000 times', function (b) {
  var crypto = require('crypto')
  var data = new Buffer('hello world')

  b.start()

  for (var i = 0; i < 200000; i++) {
    data = crypto.createHash('sha256').update(data).digest()
  }

  b.end()
})

Running the above will produce output similar to this:

NANOBENCH version 2
> git checkout 7369272 && node example.js

# sha256 200.000 times
ok ~664 ms (0 s + 663775913 ns)

# sha1 200.000 times
ok ~564 ms (0 s + 563784403 ns)

# sha256 200.000 times
ok ~575 ms (0 s + 575039783 ns)

ok ~1.8 s (1 s + 802600099 ns)

API

benchmark(name, run)

Add a new benchmark. run is called with a benchmark object, b that has the following methods

  • b.start() - Start the benchmark. If not called the bench will be tracked from the beginning of the function.
  • b.end() - End the benchmark.
  • b.error(err) - Benchmark failed. Report error.
  • b.log(msg) - Log out a message
benchmark.skip(name, run)

Skip a benchmark.

benchmark.only(name, run)

Only run this benchmark.

CLI

If you have multiple benchmarks as different files you can use the cli benchmark runner to run them all

npm install -g nanobench
nanobench benchmarks/*.js

Parser

An parser for the output format is included as well. You can require it from node using

var parse = require('nanobench/parse')
var output = parse(outputAsString)
console.log(output)

If you parse the above example output an object similar to this will be printed out

{ type: 'NANOBENCH',
  version: 2,
  command: 'git checkout 7369272 && nanobench example.js',
  benchmarks:
   [ { name: 'sha256 200.000 times',
       output: [],
       error: null,
       time: [Object] },
     { name: 'sha1 200.000 times',
       output: [],
       error: null,
       time: [Object] },
     { name: 'sha256 200.000 times',
       output: [],
       error: null,
       time: [Object] } ],
  error: null,
  time: [ 1, 802600099 ] }

License

MIT

FAQs

Package last updated on 26 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc