RegExp test / search / match vs. indexOf (v79)

Revision 79 of this benchmark created on


Preparation HTML

<script>
  var str = JSON.stringify([
  {
    "fgfhfgfgf": "556560b766605c41d66d5910",
    "_id": "556560b766605c41d66d5910",
    "index": 0,
    "guid": "b0057de2-b2b9-4f5e-8a10-3259e54ac5ae",
    "isActive": true,
    "balance": "$3,798.63",
    "picture": "http://placehold.it/32x32",
    "age": 40,
    "eyeColor": "blue",
    "name": "Shawn Evans",
    "gender": "female",
    "company": "FOSSIEL",
    "email": "shawnevans@fossiel.com",
    "phone": "+1 (956) 479-2930",
    "address": "879 Meserole Avenue, Norvelt, Indiana, 428",
    "about": "Cillum qui dolor quis sunt do aliquip aliqua pariatur ut laborum. Anim sit dolor tempor fugiat mollit nostrud veniam ad velit elit. Ea commodo ad incididunt voluptate.\r\n",
    "registered": "2014-04-20T14:33:16 -04:00",
    "latitude": -40.01082,
    "longitude": -118.957523,
    "tags": [
      "consequat",
      "ex",
      "non",
      "irure",
      "id",
      "sint",
      "eu"
    ],
    "friends": [
      {
        "id": 0,
        "name": "Keisha Duncan"
      },
      {
        "id": 1,
        "name": "Blanca Cantu"
      },
      {
        "id": 2,
        "name": "Deidre Cotton"
      }
    ],
    "greeting": "Hello, Shawn Evans! You have 1 unread messages.",
    "favoriteFruit": "apple"
  },
  {
    "_id": "556560b74f4b9e71e73d7856",
    "index": 1,
    "guid": "92c770b3-80b8-4bdc-aad4-9a2330bb0a23",
    "isActive": true,
    "balance": "$1,315.39",
    "picture": "http://placehold.it/32x32",
    "age": 29,
    "eyeColor": "brown",
    "name": "Lucas Pacheco",
    "gender": "male",
    "company": "MOTOVATE",
    "email": "lucaspacheco@motovate.com",
    "phone": "+1 (988) 541-2454",
    "address": "589 Gunther Place, Carrsville, Washington, 520",
    "about": "Deserunt cillum magna ut irure nostrud dolor sunt excepteur anim enim. Qui dolore fugiat nulla velit velit fugiat proident nostrud nulla exercitation non. Tempor tempor et consequat consequat aute eiusmod commodo veniam ad veniam laborum.\r\n",
    "registered": "2015-04-24T03:13:02 -04:00",
    "latitude": -45.336031,
    "longitude": 150.45798,
    "tags": [
      "id",
      "laboris",
      "ea",
      "officia",
      "laborum",
      "minim",
      "labore"
    ],
    "friends": [
      {
        "id": 0,
        "name": "Jackson Charles"
      },
      {
        "id": 1,
        "name": "Burt Cline"
      },
      {
        "id": 2,
        "name": "Weiss Randall"
      }
    ],
    "greeting": "Hello, Lucas Pacheco! You have 10 unread messages.",
    "favoriteFruit": "strawberry"
  },
  {
    "_id": "556560b7a46b9075e0196ceb",
    "index": 2,
    "guid": "ee7bd878-7759-4805-93ad-dff5358c9127",
    "isActive": true,
    "balance": "$2,162.78",
    "picture": "http://placehold.it/32x32",
    "age": 28,
    "eyeColor": "green",
    "name": "Haynes Mccarthy",
    "gender": "male",
    "company": "DUOFLEX",
    "email": "haynesmccarthy@duoflex.com",
    "phone": "+1 (982) 465-2986",
    "address": "964 Amity Street, Clinton, Montana, 3904",
    "about": "Nostrud excepteur exercitation aliquip deserunt pariatur enim amet aute qui. Aliquip est dolore dolor deserunt irure laborum cillum dolor. Cillum id est aliquip aliquip sunt anim tempor officia est. Amet Lorem consectetur sint nulla incididunt est occaecat. Do aute enim est laboris laboris cillum culpa ea. Nulla velit id labore aliquip voluptate ex.\r\n",
    "registered": "2014-07-31T00:55:13 -04:00",
    "latitude": -75.735289,
    "longitude": 104.668396,
    "tags": [
      "anim",
      "do",
      "ea",
      "reprehenderit",
      "laboris",
      "commodo",
      "ea"
    ],
    "friends": [
      {
        "id": 0,
        "name": "Bates Mayo"
      },
      {
        "id": 1,
        "name": "Koch Cardenas"
      },
      {
        "id": 2,
        "name": "Harrison Bishop"
      }
    ],
    "greeting": "Hello, Haynes Mccarthy! You have 7 unread messages.",
    "favoriteFruit": "apple"
  },
  {
    "_id": "556560b75909befce91e6e1e",
    "index": 3,
    "guid": "c6606f4c-c424-4614-9ccf-eb24012f6469",
    "isActive": true,
    "balance": "$3,982.88",
    "picture": "http://placehold.it/32x32",
    "age": 21,
    "eyeColor": "brown",
    "name": "Stephens Mercer",
    "gender": "male",
    "company": "ZOID",
    "email": "stephensmercer@zoid.com",
    "phone": "+1 (854) 545-3206",
    "address": "332 Autumn Avenue, Makena, New Mexico, 2363",
    "about": "Fugiat reprehenderit consectetur ullamco deserunt. Mollit amet adipisicing sunt voluptate mollit elit non Lorem ut excepteur exercitation minim magna. Esse consectetur adipisicing magna aliqua exercitation anim quis officia et commodo.\r\n",
    "registered": "2014-01-20T15:13:25 -04:00",
    "latitude": -48.455294,
    "longitude": -129.759485,
    "tags": [
      "dolore",
      "id",
      "cupidatat",
      "qui",
      "deserunt",
      "ea",
      "pariatur"
    ],
    "friends": [
      {
        "id": 0,
        "name": "Bridgette Craig"
      },
      {
        "id": 1,
        "name": "Maryellen Saunders"
      },
      {
        "id": 2,
        "name": "Mclaughlin Oneal"
      }
    ],
    "greeting": "Hello, Stephens Mercer! You have 4 unread messages.",
    "favoriteFruit": "apple"
  },
  {
    "_id": "556560b7154ca98f4e1dec03",
    "index": 4,
    "guid": "161c6649-9dc8-4e19-8f61-a99f9ffa0543",
    "isActive": true,
    "balance": "$2,613.57",
    "picture": "http://placehold.it/32x32",
    "age": 30,
    "eyeColor": "green",
    "name": "Rosemarie Levy",
    "gender": "female",
    "company": "NORSUL",
    "email": "rosemarielevy@norsul.com",
    "phone": "+1 (837) 545-2870",
    "address": "803 Cumberland Street, Loveland, Colorado, 8884",
    "about": "Sit anim est non elit aliquip Lorem enim mollit id exercitation culpa quis. Do irure dolor laborum et consequat ullamco. Quis culpa fugiat do occaecat adipisicing ipsum labore mollit. Ad cillum id voluptate consectetur incididunt dolore non laboris. Dolor exercitation ad exercitation et.\r\n",
    "registered": "2014-11-21T22:37:15 -04:00",
    "latitude": 29.446521,
    "longitude": 69.509939,
    "tags": [
      "deserunt",
      "reprehenderit",
      "qui",
      "tempor",
      "est",
      "enim",
      "non"
    ],
    "friends": [
      {
        "id": 0,
        "name": "Cathleen Griffin"
      },
      {
        "id": 1,
        "name": "Beulah Hester"
      },
      {
        "id": 2,
        "name": "Staci Carney"
      }
    ],
    "greeting": "Hello, Rosemarie Levy! You have 10 unread messages.",
    "favoriteFruit": "strawberry"
  }
]);
  var match = '__proto__';
</script>

Setup

var precompiledRegex = /(__proto__)/;

Test runner

Ready to run.

Testing in
TestOps/sec
test
/(__proto__)/.test(str);
ready
search
str.search(/(__proto__)/) > -1;
ready
match
str.match(/(__proto__)/).length > 0;
ready
indexOf
str.indexOf(/(__proto__)/) > -1;
ready
precompiled test
precompiledRegex.test(str);
ready
precompiled search
str.search(precompiledRegex) > -1;
ready
precompiled match
str.match(precompiledRegex).length > 0;
ready
precompiled indexOf
str.indexOf(precompiledRegex) > -1;
ready
indexOf string primitive
str.indexOf('__proto__') > -1
ready
Primitive comparison
str === "__proto__"
ready
Substring
str.substring(0,match.length) === match
ready

Revisions

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