Get Cookies RegEx vs indexOf

Benchmark created on


Description

Compare getting a particular cookie from document.cookie using either a regex or indexOf

Preparation HTML

<script>
  document.cookie="TEST_COOKIE=RegEx_vs_indexOf";function getCookieRegEx(c,a){var b=a.match(RegExp(c+"=([^;]*)"));return b&&b.length>0?b[1]:""}function getCookieIndexOf(c,a){var c=" "+c+"=",b,a=" "+a+";";return(b=a.indexOf(c))>=0?(b+=c.length,a=a.substring(b,a.indexOf(";",b))):""};
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Get Cookie RegEx
getCookieRegEx("TEST_COOKIE", document.cookie);
ready
Get Cookie IndexOf
getCookieIndexOf("TEST_COOKIE", document.cookie);
ready

Revisions

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