Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
React useCallback hook vs. custom hook (React 18)
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
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
Browser:
Chrome 133
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
ComponentWithOuterFunctionUseCallback
1005868.0 Ops/sec
ComponentWithUseCallback
993201.9 Ops/sec
HTML Preparation code:
<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.production.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.production.min.js"></script> <div id="root"></div> </body> </html>
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'))