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

karma-bench

v0.1.3

Published

Karma plugin for run benchmarks.js tests

Downloads

3

Readme

karma-bench

A Karma plugin to run Benchmark.js v2

Based on karma-benchmark plugin, but it don't break tests functions context

Installation

npm install karma-bench --save-dev

Karma Configuration

Reporting results on the command line

To see jsPerf style results on the command line, install karma-benchmark-reporter:

npm install karma-benchmark-reporter --save-dev

Then, in karma.conf.js, add benchmark to the list of reporters:

module.exports = function(config) {
    config.set({
        // Other Karma config here...
        frameworks: ['bench'],
        reporters: ['benchmark']
    });
};

Run Karma:

karma start

Then, you'll then see output that looks like:

Chrome 51.0.2704 (Mac OS X 10.11.5)  Array iteration: util.each at 19356910 ops/sec
Chrome 51.0.2704 (Mac OS X 10.11.5)  Array iteration: Array.forEach at 2567531 ops/sec
Chrome 51.0.2704 (Mac OS X 10.11.5)  Array search: util.contains at 12635982 ops/sec
Chrome 51.0.2704 (Mac OS X 10.11.5)  Array search: Array.indexOf at 5828437 ops/sec
Chrome 51.0.2704 (Mac OS X 10.11.5)
  Array iteration: util.each at 19356910 ops/sec (7.54x faster than Array.forEach)
  Array search: util.contains at 12635982 ops/sec (2.17x faster than Array.indexOf)

Timeouts

As large suites of Benchmarks take a long time to run, you may need to increase Karma's timeout from it's default of 60000.

captureTimeout: 60000

Writing Benchmarks

Suites and benchmarks are defined using a wrapper for Benchmark.js in the form of the suite and benchmark globals.

Typical

In this example, a suite is defined that pits _.each against the native Array.forEach method:

suite('Array iteration', function() {
    benchmark('_.each', function() {
        _.each([1, 2, 3], function(el) {
            return el;
        });
    });

    benchmark('native forEach', function() {
        [1, 2, 3].forEach(function(el) {
            return el;
        });
    });
});

Suite options

Suite options are the same as in Benchmark.js.

See the Benchmark.js Suite constructor API docs for a full list of options.

suite('Array iteration', function() {
    benchmark('_.each', {
        fn: function () {
            _.each(this.list, function(number) {
                return number;
            });
        },
        setup: function() {
            this.list = [5, 4, 3];
        },
        teardown: function() {
            this.list = null;
        }
    });
}, {
    onCycle: function(event) {
        var suite = this;
        var benchmark = event.target;
        console.log('Cycle completed for ' + suite.name + ': ' + benchmark.name);
    }
});

Benchmark options

Benchmark options are the same as in Benchmark.js.

See the Benchmark.js Benchmark constructor API docs for a full list of options.