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

talladega

v1.1.0

Published

jsperf in the console, because there can't be two number ones

Downloads

4

Readme

shake and bake

🏁🏎talladega

Remember jsperf.com? It's gone now, for some reason. Probably best not to ask questions. This works instead (for v8, anyway). See ./examples for usage examples. But remember: microbenchmarks are stupid. This is mostly useful to show you how nonintuitive your results can be.

it's all like

talladega

usage

It works a little like a simple unit test utility, like tape. Create a file and require talladega.

const talladega = require('talladega');

You need to name your benchmark:

const name = 'String concatenation vs. array join';

Then, declare an array of specs. Each spec is an object representing one of your cases to be benchmarked. talladega will compare the performance of each spec and display the graph side by side. A spec object must at least have a name labeling it and a fn string (or function) containing the actual code to be measured. In fact, it is exactly the object you pass to a Benchmark.js constructor! Any of the options available to Benchmark instances can also be used in a spec object.

const specs = [
	{
		name: 'array join',
		fn: '["Shake ", "and ", "bake!"].join("")'
	},
	{
		name: 'string concat',
		fn: '"Shake " + "and "+ "bake!"'
	}
]
⚠️ However...
  • unlike in Benchmark.js, you must always declare a name and a fn (you cannot pass a function directly)
  • all functions are going to be serialized, because the spec object will be passed to a child process so that each spec can be benchmarked on a separate processor core. Be careful with this: it means that you can't use code from the outer context in any of your spec functions or methods.

Finally, the optional third argument to talladega is an object of options.

  • expectedTime: A number of milliseconds to wait before the UI starts to complain that it's taking a while. Default 6000.
  • color: A string representing a terminal color, like green or whatever. Default cyan.

Then, call talladega(name, specs options). The script will take over your terminal window with a visual display of results.

Obviously you can do this all shorter:

require('talladega')('String concatenation vs. array join', [
	{
		name: 'array join',
		fn: '["Shake ", "and ", "bake!"].join("")'
	},
	{
		name: 'string concat',
		fn: '"Shake " + "and "+ "bake!"'
	}
], { color: 'yellow' });

but that doesn't make it faster or anything.

why is all the code in strings, bro

In order to prevent javascript VM deopts that would make your already-dubious microbenchmarks useless, the underlying benchmark.js engine stringifies your code and modifies it anwyay. You can declare your fn, setup, etc as functions if you like syntax highlighting, but it can be misleading, because you might be tempted to use variables from the outer context of your benchmark file in those functions--and that won't work. I chose stringifying for the examples so it would be extra clear that weird things are happening to your code.