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

@jalik/benchmark

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jalik/benchmark

Utilities to benchmark code.

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

@jalik/benchmark

GitHub package.json version Build Status GitHub GitHub last commit GitHub issues npm

Measure a single function

To measure a single function, use measure(func, iterations).

import { measure } from '@jalik/benchmark';

function logHelloWorld() {
  console.log('hello world');
}

// Run function 1000 times
const result = measure(logHelloWorld, 1000);

The result object of a measure looks like this:

interface MeasureResult {
  average: number;
  fastest: number;
  ips: number;
  ipsAccuracy: number;
  ipsRounded: number;
  iterations: number;
  median: number;
  slowest: number;
  total: number;
}

You can show measure result in the console with logMeasureResult(result).

import { logMeasureResult } from '@jalik/benchmark';

// const result = measure(func, iterations);
logMeasureResult(result);
iterations/s: 82 ±-0.36%
total: 1224.95 ms
average: 12.25 ms
median: 11.93 ms
fastest: 11.58 ms
slowest: 24.43 ms

Measure several functions

To measure several functions, use benchmark(funcs, iterations).

import { benchmark } from '@jalik/benchmark';

function incrementPlusPlus() {
  for (let i = 0; i < 10000; i++) {
    // do something
  }
}

function incrementPlusEqual() {
  for (let i = 0; i < 10000; i += 1) {
    // do something
  }
}

const funcs = {
  incrementPlusPlus,
  incrementPlusEqual,
};

// Run each function 1000 times 
const result = benchmark(funcs, 1000);

The result object of a benchmark looks like this:

interface BenchmarkResult {
  [key: string]: MeasureResult;
}

You can show benchmark result in the console with logBenchmarkResult(result).

import { logBenchmarkResult } from '@jalik/benchmark';

const result = benchmark({
  doSomethingSlow: () => { /* ... */ },
  doSomethingFast: () => { /* ... */ },
}, 1000);

logBenchmarkResult(result);
#1 doSomethingFast
iterations/s: 1250 ±0.00%
total: 8.00 ms
average: 0.80 ms
median: 1.00 ms
fastest: 0.00 ms
slowest: 1.00 ms

#2 doSomethingSlow
iterations/s: 40 ±0.00%
total: 250.00 ms
average: 25.00 ms
median: 25.00 ms
fastest: 24.00 ms
slowest: 27.00 ms

Changelog

History of releases is in the changelog.

License

The code is released under the MIT License.

Keywords

FAQs

Package last updated on 17 Apr 2020

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