GithubHelp home page GithubHelp logo

layershifter / react-benchmark Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rowno/react-benchmark

0.0 3.0 0.0 798 KB

A tool for benchmarking the render performance of React components

License: ISC License

JavaScript 100.00%

react-benchmark's Introduction

react-benchmark

Build Status Dependency Status

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 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.
  --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.

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

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.

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.

react-benchmark's People

Contributors

rowno avatar

Watchers

James Cloos avatar Oleksandr Fediashov avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.