Code Monkey home page Code Monkey logo

micro-bmark's Introduction

micro-bmark

Benchmark your node.js projects with nanosecond resolution.

  • Utilizes node.js process.hrtime for 1ns resolution
  • Colorful formatting with nice units
  • No dependencies, only ~150 lines of code: as lightweight as possible to not interfere with benchmarked code
  • No code for estimating running time - specify samples manually
  • Shows relative margin of error, min/max runs only if it's high

Usage

npm install --save-dev micro-bmark
import * as bench from 'micro-bmark';
await bench.mark('printing', () => Promise.resolve(0));

const { mark, compare, run } = bench; // Or, use as such
run(async () => {
  await mark('base', () => Promise.resolve(1));
  await mark('sqrt', 10000, () => Math.sqrt(2));
  await compare('math', 5000, {
    lib1: () => Math.sqrt(2),
    lib2: () => Math.sqrt(3)
  });
  // bench.utils.logMem(); // Log current RAM
  // console.log(bench.utils.getTime(), bench.utils.formatD(bench.utils.getTime())); // Get current time in nanoseconds
});

Example output:

getPublicKey() x 6,072 ops/sec @ 164μs/op ± 8.22% (min: 143μs, max: 17ms)
sign x 4,980 ops/sec @ 200μs/op
signSync x 4,671 ops/sec @ 214μs/op
verify x 969 ops/sec @ 1ms/op
recoverPublicKey x 890 ops/sec @ 1ms/op
getSharedSecret aka ecdh x 585 ops/sec @ 1ms/op
  • await bench.run(args?, callback): Runs bunch of suites. Not required
  • await bench.mark(label?, samples?, callback): Measures callback (can be async) samples times
  • await bench.compare(label, samples, map): mark, but compares runs between object values
    • map: { a: () => {}, b: () => {} }
  • bench.utils.logMem(): undefined: Logs memory usage
  • bench.utils.getTime(): bigint: Returns current time in bigint.

License

MIT License

Copyright (c) 2020 Paul Miller (https://paulmillr.com), (c) 2010-2016 Mathias Bynens, John-David Dalton, (c) Robert Kieffer from JSLitmus.js

micro-bmark's People

Contributors

paulmillr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

shigoto-dev19

micro-bmark's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.