regex vs array index for string checking

Benchmark created by REGEX VS ARRAY INDEX on


Description

5:15 dditthardt /^\//

5:15 ajacksified commandRegister: (msg) -> return !(msg[0] == "/")

5:15 dditthardt matches / anchored to beginning of line

5:16 ajacksified I bet mine's faster

5:16 dditthardt nope not a chance lol

Setup

var msg = "/imacommand"
    var regex = new RegExp("^[^/](.+)$")
    var matcher = "/"

Test runner

Ready to run.

Testing in
TestOps/sec
Array Accessor
msg[0] == matcher
ready
Regex Match
regex.exec(msg)
ready

Revisions

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

  • Revision 1: published by REGEX VS ARRAY INDEX on