Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
How to benchmark react component?

I want to benchmark rendering of a React component so that I could make incremental improvements.

I came up with this prototype for use with react v18:

import {
  useEffect,
} from 'react';
import {
  createRoot,
} from 'react-dom';
import {
  JsonView,
} from '../components/JsonView';

const render = (root) => {
  return new Promise((resolve) => {
    root.render(<div ref={() => {
      resolve(undefined);
    }}
    >
      <JsonView
        activePath={null}
        entries={{foo: 'bar'}}
        expanded
        highlights={[]}
        onActivePathChange={() => {}}
      />
    </div>);
  });
};

const TestPage = () => {
  useEffect(() => {
    const sandbox = document.createElement('div');

    document.body.appendChild(sandbox);

    const root = createRoot(sandbox);

    (async () => {
      const startTime = Date.now();
      const runTime = 1_000;

      let renderCount = 0;

      while (Date.now() - startTime < runTime) {
        await render(root);

        renderCount++;
      }

      console.log('done', renderCount);
    })();

    return () => {
      document.body.removeChild(sandbox);
    };
  }, []);

  return <div />;
};

export default TestPage;
  • JsonView is the component that I want to benchmark.
  • ref is used to identify when div is created.
  • startTime / runTime are used to limit test suite run time.

This works well – I am getting consistent benchmark outputs and making changes to the component shows performance improvement / degradation.

However, I was wondering if this is the right way to benchmark a React component or if I should be using another mechanism?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!