<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
<div id="dest"></div>
const Hello = ({toWhat}) => React.createElement('div', null, `Hello ${toWhat}`);
ReactDOM.render(
React.createElement(Hello, {toWhat: 'World'}, null),
document.getElementById('dest')
);
function Hello({ toWhat }) {
return React.createElement('div', null, `Hello ${toWhat}`);
}
ReactDOM.render(
React.createElement(Hello, {toWhat: 'Worldd'}, null),
document.getElementById('dest')
);
const Hello = ({toWhat}) => React.createElement('div', null, `Hello ${toWhat}`);
ReactDOM.render(
React.createElement(Hello, {toWhat: 'Worldd'}, null),
document.getElementById('dest')
);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Function | |
Const anon function |
Test name | Executions per second |
---|---|
Function | 378098.0 Ops/sec |
Const anon function | 510912.3 Ops/sec |
Benchmark Explanation
MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The provided JSON represents two benchmark definitions for testing the performance of two different approaches to creating React components: using a function declaration versus using an anonymous const function.
Options Compared
The two benchmark definitions compare the execution time of:
function Hello({toWhat}) { ... }
const Hello = ({toWhat}) => { ... };
Both approaches create a React component named Hello
that renders a div
element with the text "Hello World".
Pros and Cons of Each Approach
Library and Purpose
Both benchmark definitions use two libraries:
ReactDOM.render
function used to render the components in the DOM.Special JS Feature or Syntax
Both benchmark definitions use:
Other Alternatives
If you're interested in exploring alternative approaches, consider the following options:
Keep in mind that these alternatives may require additional setup and configuration, and may not be directly comparable to the original benchmark definitions.