Regex vs indexOf (v2)

Revision 2 of this benchmark created on


Setup

const text = document.documentElement.outerHTML

Test runner

Ready to run.

Testing in
TestOps/sec
regex
return /<body[^>]*?>(.*?)<\/body>/s.exec(text)[1]
ready
indexOf
let i = text.indexOf('<body')
if (i < 0) return
i = text.indexOf('>', i + 5)
if (i < 0) return
const start = i + 1
const end = text.indexOf('</body>', start)
if (end < 0) return
return text.substring(start, end)
ready
indexOf, without error handling
let i = text.indexOf('<body')
i = text.indexOf('>', i + 5)
const start = i + 1
const end = text.indexOf('</body>', start)
return text.substring(i, end)
ready
indexOf, but inlined and no error hadling
const start = text.indexOf('>', text.indexOf('<body') + 5) + 1
const end = text.indexOf('</body>', start)
return text.substring(start, end)

ready

Revisions

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