Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JSON Parse vs regex
(version: 4)
Comparing performance of:
JSON vs Regex vs String search vs indexOf
Created:
2 years ago
by:
Registered User
Jump to the latest result
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); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
JSON
Regex
String search
indexOf
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
6 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36
Browser/OS:
Chrome 140 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
JSON
370484.2 Ops/sec
Regex
1237626.8 Ops/sec
String search
560852.1 Ops/sec
indexOf
558444.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
It seems like we have a large dataset of benchmark test cases, each with its own set of inputs (data and comments) and a corresponding benchmark definition for a specific programming language or technology. The benchmark results are also provided, showing the execution performance of different browsers on various devices. The task at hand appears to be analyzing these test cases to identify any trends, patterns, or insights that can help us understand how different programming languages or technologies perform in terms of execution speed, memory usage, and other relevant metrics. To get started, let's break down the data into smaller chunks and focus on one aspect at a time. We could begin by examining the benchmark definitions themselves, looking for commonalities or differences between them. What do you think we should tackle first?
Related benchmarks:
String split vs Regex 02
String split using regex vs string v3
JSON.stringify fork, larger item 2
String split separator vs regex
Hello 124
Comments
Confirm delete:
Do you really want to delete benchmark?