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

race.js

v0.1.4

Published

Pit JavaScript libraries against each other

Downloads

53

Readme

RACE!!!11

Note: What follows is currently a lie. I am practicing Readme Driven Development; i.e., I am writing this out before having actually implemented it. This is to help me work through how exactly I want the library to work. When it's implemented for real, I will (obviously) erase this message.

Purpose

You've got a sweet library that does what some other library already does, and you want to race them to demonstrate that yours is superior.

Or, if you don't want to be a jerk about it... maybe you just want to point out the differences and trade-offs between different implementations of the same functionality.

This library serves two purposes:

  1. To actually compare the performance of different implementations
  2. To verify that different implementations actually produce the same results (if desired)

Usage

Let's say we have two functions, sumIterative() and sumRecursive(), that do the same thing: sum up the values in an array. To race them, first we create a Race object:

var sumRace = new Race({
  description: 'sumIterative() vs. sumRecursive()',

  impls: {
    'simple': sumIterative,
    'fast': sumRecursive
  },

  inputs: [
    {
      name: 'Small array',
      values: [Race.integers(10)],
      size: 10
    },

    {
      name: 'Medium array',
      values: [Race.integers(100)],
      size: 100
    },

    {
      name: 'Large array',
      values: [Race.integers(1000)],
      size: 1000
    }
  ],

  comparer: function(x, y) {
    if (x.length !== y.length) {
      return false;
    }

    for (var i = 0; i < x.length; ++i) {
      if (x[i] !== y[i]) {
        return false;
      }
    }

    return true;
  }
});

Then we begin the race and pass in some callbacks:

sumRace.start({
  start: function(race) {
    /*
     * Here race will be a Race object like the one described above, with description, impls, etc.
     */
  },

  result: function(result) {
    /*
     * Here result will be a Race.Result object like this:
     *
     * {
     *   impl: 'simple',
     *   input: { name: 'Small input', size: 10 },
     *   perf: 1000000.0
     * }
     */
  },

  group: function(resultGroup) {
    /*
     * Here resultGroup will be a Race.ResultGroup object like this:
     *
     * {
     *   input: { name: 'Small input', size: 10 },
     *   results: {
     *     'simple': 1000000.0,
     *     'fast': 1500000.0
     *   }
     * }
     */
  },

  complete: function(resultGroups) {
    /*
     * Here resultGroups will be an array of Race.ResultGroup objects, i.e.:
     *
     * [
     *   {
     *     input: { name: 'Small input', size: 10 },
     *     results: {
     *       'simple': 1000000.0,
     *       'fast': 1500000.0
     *     }
     *   },
     *   {
     *     input: { name: 'Medium input', size: 100 },
     *     results: {
     *       'simple': 500000.0,
     *       'fast': 750000.0
     *     }
     *   },
     *   ...
     * ]
     */
  }
});

You can run multiple races in sequence using the Race.Marathon object:

var marathon = new Race.Marathon();

marathon.add(new Race({
  /*
   * All the properties explained above.
   */
}));

marathon.add(new Race({
  /*
   * Add as many races as you like.
   */
}));

marathon.start({
  /*
   * All the same callbacks as you can pass to `Race.start()`, PLUS...
   */
  marathonComplete: function() {
    /*
     * Run when all races in the marathon have finished.
     */
  }
});