Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
JSON Parse vs regex
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0
Browser:
Firefox 123
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Benchmark engine:
Benchmark.js
indexOf
916K/s
String search
770K/s
Regex
335K/s
JSON
62K/s
View exact numbers
Test name
Executions per second
✓
indexOf
915,527 Ops/sec
String search
770,452 Ops/sec
Regex
335,356 Ops/sec
JSON
61,700 Ops/sec
Script Preparation code:
var entries = [{ "data": "random_string_one", "comment": "{\"random_other_field_one\":\"this is a bunch of sample data\",\"random_other_field_two\":\"this is another set of sample data\",\"random_other_field_three\":\"this is another bit of sample data\",\"random_other_field_four\":\"this is another glob of sample data\",\"segregationRequirement\":2}" }, { "data": "random_string_one", "comment": "{\"random_other_field_one\":\"this is a bunch of sample data\",\"random_other_field_two\":\"this is another set of sample data\",\"random_other_field_three\":\"this is another bit of sample data\",\"random_other_field_four\":\"this is another glob of sample data\",\"segregationRequirement\":221}" }, { "data": "random_string_one", "comment": "{\"random_other_field_one\":\"this is a bunch of sample data\",\"random_other_field_two\":\"this is another set of sample data\",\"random_other_field_three\":\"this is another bit of sample data\",\"random_other_field_four\":\"this is another glob of sample data\",\"segregationRequirement\":2}" }, { "data": "random_string_one", "comment": "{\"random_other_field_one\":\"this is a bunch of sample data\",\"random_other_field_two\":\"this is another set of sample data\",\"random_other_field_three\":\"this is another bit of sample data\",\"random_other_field_four\":\"this is another glob of sample data\",\"segregationRequirement\":2}" }, { "data": "random_string_one", "comment": "{\"random_other_field_one\":\"this is a bunch of sample data\",\"random_other_field_two\":\"this is another set of sample data\",\"random_other_field_three\":\"this is another bit of sample data\",\"random_other_field_four\":\"this is another glob of sample data\",\"segregationRequirement\":221}" }, { "data": "random_string_one", "comment": "{\"random_other_field_one\":\"this is a bunch of sample data\",\"random_other_field_two\":\"this is another set of sample data\",\"random_other_field_three\":\"this is another bit of sample data\",\"random_other_field_four\":\"this is another glob of sample data\",\"segregationRequirement\":2}" }, { "data": "random_string_one", "comment": "{\"random_other_field_one\":\"this is a bunch of sample data\",\"random_other_field_two\":\"this is another set of sample data\",\"random_other_field_three\":\"this is another bit of sample data\",\"random_other_field_four\":\"this is another glob of sample data\",\"segregationRequirement\":221}" }, { "data": "random_string_one", "comment": "{\"random_other_field_one\":\"this is a bunch of sample data\",\"random_other_field_two\":\"this is another set of sample data\",\"random_other_field_three\":\"this is another bit of sample data\",\"random_other_field_four\":\"this is another glob of sample data\",\"segregationRequirement\":2}" }, { "data": "random_string_one", "comment": "{\"random_other_field_one\":\"this is a bunch of sample data\",\"random_other_field_two\":\"this is another set of sample data\",\"random_other_field_three\":\"this is another bit of sample data\",\"random_other_field_four\":\"this is another glob of sample data\",\"segregationRequirement\":221}" }, { "data": "random_string_one", "comment": "{\"random_other_field_one\":\"this is a bunch of sample data\",\"random_other_field_two\":\"this is another set of sample data\",\"random_other_field_three\":\"this is another bit of sample data\",\"random_other_field_four\":\"this is another glob of sample data\",\"segregationRequirement\":221}" }, { "data": "random_string_one", "comment": "{\"random_other_field_one\":\"this is a bunch of sample data\",\"random_other_field_two\":\"this is another set of sample data\",\"random_other_field_three\":\"this is another bit of sample data\",\"random_other_field_four\":\"this is another glob of sample data\",\"segregationRequirement\":2}" }, { "data": "random_string_one", "comment": "{\"random_other_field_one\":\"this is a bunch of sample data\",\"random_other_field_two\":\"this is another set of sample data\",\"random_other_field_three\":\"this is another bit of sample data\",\"random_other_field_four\":\"this is another glob of sample data\",\"segregationRequirement\":2}" }, { "data": "random_string_one", "comment": "{\"random_other_field_one\":\"this is a bunch of sample data\",\"random_other_field_two\":\"this is another set of sample data\",\"random_other_field_three\":\"this is another bit of sample data\",\"random_other_field_four\":\"this is another glob of sample data\",\"segregationRequirement\":2}" }, { "data": "random_string_one", "comment": "{\"random_other_field_one\":\"this is a bunch of sample data\",\"random_other_field_two\":\"this is another set of sample data\",\"random_other_field_three\":\"this is another bit of sample data\",\"random_other_field_four\":\"this is another glob of sample data\",\"segregationRequirement\":221}" }, { "data": "random_string_one", "comment": "{\"random_other_field_one\":\"this is a bunch of sample data\",\"random_other_field_two\":\"this is another set of sample data\",\"random_other_field_three\":\"this is another bit of sample data\",\"random_other_field_four\":\"this is another glob of sample data\",\"segregationRequirement\":2}" } ];
Tests:
JSON
const arr = []; for (const entry of entries) { const value = JSON.parse(entry.comment); arr.push(value.segregationRequirement); }
Regex
const arr = []; const re = /"segregationRequirement":\s*(\d+)[,}]/; for (const entry of entries) { const match = entry.comment.match(re) arr.push(match[1]); }
String search
const arr = []; for (const entry of entries) { const found = entry.comment.includes('"segregationRequirement":2'); arr.push(found); }
indexOf
const arr = []; for (const entry of entries) { const found = entry.comment.indexOf('"segregationRequirement":2') !== -1; arr.push(found); }