npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bench-trial

v3.2.3

Published

Runs one or multiple benchmark tests

Downloads

11

Readme

Bench trial

Build Status codecov Coverage Status All Contributors

Runs one or multiple benchmark tests

Install

npm install -g bench-trial

Usage

bench-trial benchmarks/map-helper-vs-entity.js -i 5

TL;DR

Runs one (or more) BenchmarkJs test multiple times enough to get less ambiguous results, includes basic testing to make sure tests are reliable.

Why?

While running benchmarkjs to compare different versions of code I found out a couple of things:

  • Ambiguous results: I noticed that the same benchmark tests were returning different results every time they executed. If they were re-run consecutively, I would get more operations per second on each benchmark. I believe the reason may be related to the v8 engine warming up and optimizing the code the more it ran, since if I let some time to "cool off" the operations per second for each test would decrease. These ambiguous results meant having to repeat tests to ensure some consistency.
  • Unreliable execution: Occasionally I made changes to the benchmarked code and would overlook that it was not executing correctly, further compounding the issue of making the results unreliable.

Solution

  • Consistency: By running benchmark tests more than once, we can get median and average results and get a bigger picture with less fluctuation. Because the tests will run multiple times in succession, the code will get optimized by the engine, and we can use the median time as a more consistent and stable metric.

  • Reliable execution: By running simple assertion tests on each suite before the actual benchmark runs, we can be sure our tests are executing correctly.

API

bench-trial <file> [-i <iterations>] [-s]
  • -i --iterations <iteration> iterations default to 10 iterations if not provided.
  • -s --skip-tests if provided, it will skip the assertion tests.

Writing your benchmark suites

The file provided to bench-trial should export an array of test suites, each test suite is an object in the form of:

{
  name: string,
  test: function,
  benchmark: function
}

| Property | Type | Description | |:---|:---|:---| | name | String | Name that describes the test you are running | | test | function | function to run assertion test against the result of the code you want to benchmark | | benchmark | function | function to pass to benchmarkjs Suite that actually runs the benchmark |

Sync vs Async

  • Synchronous methods are simple methods that expect a return value.
  • Asynchronous methods are a bit different to benchmarkjs async methods, bench-trial expects async methods to follow the error-first callbacks.

Testing

bench-trial provides a convenience method that accepts the function to execute and a value to check against the result of the code you are testing. It takes care of async vs async depending on how you set the async flag.

test(test:function, value:*)

To write your manual test see the manual test example below

Examples

  • Test synchronous code example
  • Test asynchronous code example
  • Write manual test sync/asynchronous code example

Acknowledgements

This tool is a wrapper of benchmarkjs, so all credit related to benchmarking itself really goes to them.

Thanks to Paul Molluzzo for coming up with the name bench-trial!

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

License

This project is licensed under the Apache License Version 2.0 - see the LICENSE file for details