Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@anyroad/react-component-benchmark
Advanced tools
A component utility for estimating benchmarks of React components
This project aims to provide a method for gathering benchmarks of component tree mount, update, and unmount timings.
Please note that the values returned are estimates. Since this project does not hook into the React renderer directly, the values gathered are not 100% accurate and may vary slightly because they're taken from a wrapping component. That being said, running a large sample set should give you a confident benchmark metric.
Historically, React has provided react-addons-perf
in order to help gain insight into the performance of mounting, updating, and unmounting components. Unfortunately, as of React 16, it has been deprecated. Additionally, before deprecation, it was not usable in production React builds, making it less useful for many applications.
See the examples directory for ideas on how you might integrate this into your own project, whether in your user-interface or your automated tests.
import Benchmark, { BenchmarkType } from 'react-component-benchmark';
class MyComponentBenchmark extends React.Component {
render() {
return (
<div>
<button onClick={this._start}>Run</button>
<Benchmark
component={MyComponent}
componentProps={componentProps}
onComplete={this._handleComplete}
ref={this._setBenchRef}
samples={50}
timeout={10000}
type={BenchmarkType.MOUNT}
/>
</div>
);
}
_start = () => { this._benchmark.start(); };
_handleComplete = (results) => {
console.log(results);
};
_setBenchRef = (ref) => { this._benchmark = ref; };
}
component
: typeof React.ComponentcomponentProps
: object Properties to be given to component
when renderingonComplete
: (x: BenchResultsType) => voidsamples
: number Samples to run (default 50
)timeout
: number Amount of time in milliseconds to stop running (default 10000
)type
: string One of 'mount'
, 'update'
, or 'unmount'
. Also available from BenchmarkType
.See examples/tests for various test integrations.
Note: All times and timestamps are in milliseconds. High resolution times provided when available.
startTime
: number Timestamp of when the run startedendTime
: number Timestamp of when the run completedrunTime
: number Amount of time that it took to run all samples.sampleCount
: number The number of samples actually run. May be less than requested if the timeout
was hit.samples
: Array<{ start, end, elapsed }>max
: number Maximum time elapsedmin
: number Minimum time elapsedmedian
: number Median time elapsedmean
: number Mean time elapsedstdDev
: number Standard deviation of all elapsed timesp70
: number 70th percentile for time elapsed: mean + stdDev
p95
: number 95th percentile for time elapsed: mean + (stdDev * 2)
p99
: number 99th percentile for time elapsed: mean + (stdDev * 3)
FAQs
A component utility for estimating benchmarks of React components
We found that @anyroad/react-component-benchmark demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.