I wrote a JSON library

Sean Kelly sean at invisibleduck.org
Tue May 7 11:36:19 PDT 2013


On Tuesday, 7 May 2013 at 17:13:18 UTC, Piotr Szturmaj wrote:
>
> You may find this useful: 
> https://github.com/pszturmaj/json-streaming-parser

Thanks for the link.  Unfortunately, I couldn't get it to 
compiler out of the box.  I did use the test routine you had to 
benchmark std.json and the JSON implementation from the OP of 
this thread as well as an event-based JSON parser I implemented 
for work.  On a single parse of this large (189MB) JSON file:

https://github.com/zeMirco/sf-city-lots-json

Here are my results for one parse, where "newJson" is the OP's 
JSON parser and "jepJson" is mine:

$ main
n = 1
Milliseconds to call stdJson() n times: 73054
Milliseconds to call newJson() n times: 44022
Milliseconds to call jepJson() n times: 839
newJson() is faster than stdJson() 1.66x times
jepJson() is faster than stdJson() 87.1x times


Now obviously, in many cases convenience is preferable to raw 
speed, but I think code in Phobos should be an option for both 
types of uses whenever possible.  What I'd really like to see is 
the variant-type front-end layered on top of an event-based 
parser so the user could just use parseJSON as-is to generate a 
tree of JSON objects or call the event-driven parser directly 
when performance is desired.  I don't think the parser needs to 
be resumable either, since in most cases JSON is transported in 
an HTTP message, so a plain old recursive descent parser is fine.


More information about the Digitalmars-d mailing list