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

react-benchmark

v5.1.0

Published

A tool for benchmarking the render performance of React components.

Downloads

112

Readme

react-benchmark

Demo

A tool for benchmarking the render performance of React components.

It compiles the benchmark code into a minified production bundle using Webpack and then runs it in headless Chrome to benchmark the real production code in a real production environment.

Note: the benchmark numbers aren՚t completely accurate and should only be used relatively to compare the performance difference of code changes or different implementations.

Install

yarn global add react-benchmark
# or
npm install -g react-benchmark

Usage

Usage
  $ react-benchmark <path>

Options
  <path>          Path to a JavaScript or TypeScript file that exports the function to be benchmarked.
  --debug, -d     Run a development build instead of a production build to aid debugging.
  --devtools, -t  Run Chrome in windowed mode with the devtools open.
  --cpuThrottle=X Run Chrome with CPU throttled X times.
  --version       Prints the version.
  --help          Prints this message.

Examples
  $ react-benchmark benchmark.js

The <path> file should export a function that returns the component instance you want to benchmark. For example:

import React from 'react'
import Component from './src'

export default function () {
  return <Component hello="world" />
}

You can import anything that Webpack supports out of the box and your code will be transpiled with Babel using your local Babel config. TypeScript files are also supported out of the box.

API

react-benchmark exports a ReactBenchmark class that instantiates an event emitter with a .run() method. Calling the .run() method will start the benchmark with the provided options.

const ReactBenchmark = require('react-benchmark')
const reactBenchmark = new ReactBenchmark()

reactBenchmark.on('progress', (currentStats) => {
  console.log(currentStats)
})

const result = await reactBenchmark.run('benchmark.js')

See the CLI code for a full implementation example.

.run(filepath, options)

Starts the benchmark. Returns a Promise that will resolve to a Benchmark object containing the stats once the benchmark has been completed.

filepath

Type: String

Path to the benchmark file to run. See the Usage section for more details.

options

Type: Object Default: { debug: false, devtools: false, cpuThrottle: 1 }

Optional object containing additional options.

debug

Type: Boolean Default: false

Run a development build instead of a production build to aid debugging.

devtools

Type: Boolean Default: false

Run Chrome in windowed mode with the devtools open.

cpuThrottle

Type: number Default: 1

Run Chrome with CPU throttled X times. Useful to receive more precise results between runs.

Events

webpack

Fired when the Webpack build has started.

server

Fired when the webserver has started.

chrome

Fired when Chrome has launched.

start

Fired when the actual benchmark starts.

progress

Fired every time a benchmark cycle has been completed. Gets passed a Benchmark object with the current stats. This event will be fired multiple times per run.

console

Fired every time something is logged to Chrome՚s console. Gets passed a {type, text} object.

License

react-benchmark is released under the ISC license.

Copyright © 2018, Roland Warmerdam.