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 🙏

© 2025 – Pkg Stats / Ryan Hefner

cypress-benchmark

v1.0.3

Published

A Cypress plugin to benchmark tests

Readme

cypress-benchmark

A simple Cypress plugin to run benchmark tests.

Cypress is not meant to be used as a performance testing tool since it has some overhead that causes things to run slower. However, if you're already using Cypress and want to get some benchmarks on the performance of your app, this will at least give you a good starting point.

Setup

npm install --save-dev cypress-benchmark

There are 3 parts to this plugin package, the plugin, the commands, and the test wrapper.

plugin

Setup the plugin in your plugins file

let setupPlugin = require('cypress-benchmark/plugin')

module.exports = (on, config) => {
    /**
     * ...other plugins
     */
    setupPlugin(on)
}

If you don't already have a plugins file (typically cypress/plugins/index.js), create one with the snippet above. See https://on.cypress.io/plugins-guide for details.

commands

Import the commands in your support file.

import commands from 'cypress-benchmark/commands'

This is typically in cypress/support/index.js. See https://on.cypress.io/configuration for details.

Test wrapper

In your spec files, you can now import cypress-benchmark, and use it as if it were the global it method:

import benchmark from 'cypress-benchmark';

benchmark('My Benchmark Test', () => {
    cy.visit('...')

    cy.mark('start')
    /**
     * ...perform actions to measure
     */
    cy.mark('end')

    cy.measure('Data load time', 'start', 'end')
})

An alternative to importing the test wrapper in every spec file is to add it to the global scope in the support file where you would import commands:

import benchmark from 'cypress-benchmark';

global.benchmark = benchmark;

Now you should have benchmark available globally just like it and describe.

Usage

benchmark(name, [options], test)

Runs a test and compiles measures recorded in the test.

name: String

Required

Name of the benchmark, similar in hierarchy to a describe

options: Object

An optional set of parameters described below.

test: Function

Required

The test function to run.

benchmark should be used in conjunction with the support commands cy.mark and cy.measure which are just wrappers for the respective performance methods.

import benchmark from 'cypress-benchmark';

benchmark('My Benchmark Test', () => {
	cy.visit('/');

	cy.mark('start1');
	/**
	 * ...perform actions to measure
	 */
	cy.mark('end1');

	cy.mark('start2');
	/**
	 * ...perform some other actions to measure
	 */
	cy.mark('end2');

	cy.measure('Measure 1', 'start1', 'end1');
	cy.measure('Measure 2', 'start2', 'end2');
});

Should result in something like this in your output file:

{
	"My Benchmark Test": {
		"Measure 1": [
			41.505000030156225,
		],
		"Measure 2": [
			43.69500000029802
		]
	}
}

Options

benchmark supports an optional second parameter which allows the following options to be set:

merge: Boolean

Default: true

Determines if the new results should be merged in with the existing results. Setting to false will overwrite the output file.

runCount: Number

Default: 1

Number of times to run the test

outPath: String

Default: 'benchmark.json'

File path to write the results to. The path is relative to the Cypress root.

Support commands

The two support commands cy.mark and cy.measure simply call the respective methods from performance.