var ob = `{"aenderungen":[],"_id":"64c0fc4abd2c8bd76c9553f2","name":"Maxis","geburtsdatum":"2023-08-02T00:00:00.000Z","ICD10Code":"k k k k k ","position":0,"empfangsdatum":"2023-07-26T10:58:18.716Z","hinzugefügtVon":"6498bf3b2afb897aa26d18e6","infos":{"berichte":"ggg","puls":"hallo yazn "},"positionarr":[0,0],"stationen":[],"__v":0}`
var value = JSON.parse(ob)._id;
const value = ob.substring(25,49);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
JSON.parse() | |
String.substring |
Test name | Executions per second |
---|---|
JSON.parse() | 2022833.6 Ops/sec |
String.substring | 190171232.0 Ops/sec |
Let's dive into the world of JavaScript benchmarks!
The provided JSON represents a benchmark test case on MeasureThat.net, which compares the performance of two different approaches: JSON.parse()
and String.substring
for fetching a specific value from a JSON object.
Benchmark Definition
The test aims to determine whether it is faster to extract a value using JSON.parse()
or directly via String.substring
. The benchmark definition is as follows:
ob
JSON.parse(ob)
to parse the JSON and extract the _id
propertyString.substring(25, 49)
Options Compared
Two options are compared:
Pros and Cons
JSON.stringify()
)String.indexOf()
)Library
In this benchmark, no specific library is required or utilized. The test focuses solely on the performance comparison between two built-in JavaScript methods.
Special JS Feature/Syntax
None of the provided code utilizes special JavaScript features or syntax that would be unfamiliar to most software engineers.
Other Considerations
When considering these approaches, you may also want to think about:
JSON.parse()
can create a new object in memory, which might impact performance and memory usage for large JSON objects.Other Alternatives
If you're interested in exploring alternative approaches or methods for extracting values from JSON objects, consider:
document.getElementById()
, getElementsByClassName()
) to access JSON datafetch()
with JSON response handling) for fetching JSON dataKeep in mind that these alternatives might not be as optimized or performant as the built-in methods used in this benchmark.