Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's faster to parse lots of data (5Mb): eval or json?

I want to get, via ajax, a collection of data objects and parse them into JS data.

Currently I have 2 choices: - Server returns valid javascript code and then I eval it. - Server returns JSON object and then I eval the json object

What is the fastest of these in Firefox? (I only care about the "parsing" performance, not server or data transfer)

like image 265
AlfaTeK Avatar asked Apr 09 '10 02:04

AlfaTeK


People also ask

Is JSON fast to parse?

It's definitely much, much slower than MySQL (for a server) or SQLite (for a client) which are preferrable. Also, JSON speed depends almost solely on the implementation. For instance, you could eval() it, but not only that is very risky, it's also slower than a real parser.

Is JSON parse slow?

parse: 702 ms. Clearly JSON. parse is the slowest of them, and by some margin.

How long does it take to parse JSON?

In any case, to answer my own question, it seems that parsing JSON should take about 8 cycles per input byte on a recent Intel processor. Maybe less if you are clever. So you should expect to spend 2 or 3 seconds parsing one gigabyte of JSON data.

Is JSON parsing faster than XML?

Parsing speed varies with the technique used. Pure JavaScript parsing generally performs better with XML than with JSON, while query speed generally is faster for JSON. Both with exceptions though where the contrary is true. Using the JavaScript library jQuery imposes a steep penalty on JSON and even worse on XML.


1 Answers

Have a look at the results VinylFox came up with when he tested JSON decoding in the wild. The native functions performed best across all browsers.

like image 193
Jonathan Julian Avatar answered Sep 21 '22 10:09

Jonathan Julian