We are creating an application that uses a lot of XML parsing and I thought maybe to use JSON, because we can use JSON as an alternative to XML.
I need to test which is faster JSON or XML, but thought to ask an opinion here first.
JSON in JavaScript is native and it's fast. Certainly faster than parsing XML. But in Delphi there's no native classes for doing that.
So my question is - which is faster in Delphi, using XML or JSON parser library? Or are they equal in speed?
And if it's faster then which you prefer - Delphi Web Utils, JSON Delphi Library or JSON Toolkit
With a well written parser, XML and JSON will have more or less the same timing. You can have a slow JSON parser, and a fast XML parser.
Perhaps a bit slower for XML because the syntax is more complex than JSON's.
But the bottleneck will be mostly reading from the hard drive, not parsing the content.
We used JSON for the Client/Server of our ORM, for several reasons (but you'll find others, I don't want to troll here, just speak from our little experiment):
About parsing speed, you could take a look at our in-place parser and JSON writer from SQLite3 results. It was very optimized for speed, and fast it is. We wrote a simple but efficient JSON serialization for any TPersistent, including collections. We just add a dynamic array JSON serializer, which is also very fast.
Additional note:
All those parsers differ from the one you mentioned because they parse the JSON content and format it as text inside the input buffer: there is no memory allocation made during parsing, so it should be faster than other solutions. Text content is unescaped, fields are #0 ended, and a pointer to the beginning of the text is computed. So to access a value, you just use the pointer to get the data. It usually parses some MB of JSON content with no time.
Also take a look at the JSON parser embedded in DWS. The author claimed it was fast. But still allocated a memory block for each object.
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