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)
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.
parse: 702 ms. Clearly JSON. parse is the slowest of them, and by some margin.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With