I have json with some objects in it. And only one object from json i need. So which approach will be better for speed and performance - parse only this object or parse whole document instead?
Asked
Active
Viewed 125 times
0
-
Premature optimization is the root of all evil ;) Do whichever one requires less coding, and make a note of it. If you run into a bottleneck later on, then you can switch it. – Joel Cornett Jan 27 '14 at 08:39
-
This is my bottleneck, i parse whole data and get 7-8 seconds delay, before i got all needed data. – Outofdate Jan 27 '14 at 08:40
-
Ouch. Yeah that's pretty bad. Have you tried the other way? That should answer your question. – Joel Cornett Jan 27 '14 at 08:42
-
No, i don't. 7-8 second that's from 18 different URLs. So there is a third approach - if i make more threads to parse data. It's gonna help me. Thanks. – Outofdate Jan 27 '14 at 08:45
3 Answers
1
If you want to show only the particular JSON Object which may be either inside a JSON Object or JSON array itself then you just parse that particular JSON Object instead of parsing whole document.

Saggy
- 624
- 8
- 23
0
If you are not going to use rest of the data, you can just parse the item you only need.

Orhan Obut
- 8,756
- 5
- 32
- 42
0
In theory, just the object would get you a result faster with lesser work times. So just parse the object you need.

Aashir
- 2,621
- 4
- 21
- 37