From: Eric Mahurin Date: 2008-02-04T09:50:16+09:00 Subject: Re: [QUIZ] Parsing JSON (#155) ------=_Part_3879_12365898.1202086223329 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Feb 1, 2008 7:55 AM, Ruby Quiz wrote: > In honor of that, this week's Ruby Quiz is to write a parser for JSON. Here is another solution that uses my (somewhat) optimized 'grammar' package directly. The JSON grammar is similar to before. The next release will use an API closer to the simple Grammar0 package. http://pastie.caboo.se/147078 Also, I ported this to my development code (which is not checked in to CVS yet), to see the performance. I grabbed all of the current submissions along with the fjson and json gems to see how they compare in terms of performance. I used the previous benchmark that I posted. It also revealed bugs in these submissions. Here is the performance I found on my machine with ruby 1.8.6: ch/s author/gem ---- ---------- - oksteev (TreeTop, couldn't get it to parse a string) - Pawel Radecki (RE, mismatch) - Justin Ethier (RE lexer + parser, 71: Invalid number 0) 4054 Eric Mahurin (Grammar0, no lexer, no parser generation) 54586 Eric Mahurin (Grammar, no lexer, v0.5) 166041 Thomas Link (RE, ruby 1.9 results) 220289 json 223486 Eric Mahurin (Grammar, no lexer, unreleased) 224823 fjson (uses C extensions) 553081 Eric Mahurin (Grammar, no lexer, unreleased, w/ ruby2cext) 1522250 json (w/ C extensions) Note that the Grammar variants don't have the advantage of using RegExp where you get some C performance. But, in my dev code, I'm using ruby2cext to get a little more performance. You could integrate a RegExp lexer with a Grammar parser, also. ------=_Part_3879_12365898.1202086223329--