Split vs Regex Match

Benchmark created on


Description

Benchmark Test

Test runner

Ready to run.

Testing in
TestOps/sec
Split and Reduce
const str = "script=bundle:id=1589427400:value=21995:count=4:index=4";
for (let i = 0; i < 1000000; i++) {
    const parts = str.split(":").reduce((acc, part) => {
      const [key, value] = part.split("=");
      acc[key] = value;
      return acc;
    }, {});
  }
ready
Regex Match
const str = "script=bundle:id=1589427400:value=21995:count=4:index=4";
const regex = /script=bundle:id=(\d+):value=(\d+):count=(\d+):index=(\d+)/;
  for (let i = 0; i < 1000000; i++) {
    const match = str.match(regex);
  }
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.