extract string with indexOf or regex

Benchmark created on


Setup

const myStr = "rgb(1 2 3 4)";

Test runner

Ready to run.

Testing in
TestOps/sec
Extract with indexOf
const str = myStr.slice(myStr.indexOf("("));

return str;
ready
Extract with regex
const match = myStr.match(/(.*?)\(/);
const str = match? match[1]: null;

return str;
ready

Revisions

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