HTML Preparation code:
x
 
1
<!doctype html>
2
<html>
3
  <head>
4
    <title>This is the title of the webpage!</title>
5
  </head>
6
  <body>
7
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.production.min.js"></script>
8
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.production.min.js"></script>
9
    <div id="root"></div> 
10
  </body>
11
</html>
12
Script Preparation code:
 
const useHandler = (handler) => React.useRef(handler).current;
function useHandlerComponent() {
    const testFunction = useHandler(evt => evt.preventDefault(), []);
    return React.createElement('button', {
        onClick: testFunction
    }, 'Test click');
}
function UseCallbackComponent() {
    const testFunction = React.useCallback(evt => evt.preventDefault(), []);
    return React.createElement('button', {
        onClick: testFunction
    }, 'Test click');
}
Tests:
  • ComponentWithOuterFunctionUseCallback

     
    ReactDOM.render(React.createElement(useHandlerComponent), document.getElementById('root'))
  • ComponentWithUseCallback

     
    ReactDOM.render(React.createElement(UseCallbackComponent), document.getElementById('root'))
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    ComponentWithOuterFunctionUseCallback
    ComponentWithUseCallback

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one month ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Chrome 133 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
ComponentWithOuterFunctionUseCallback 1005868.0 Ops/sec
ComponentWithUseCallback 993201.9 Ops/sec