From: Eric Mahurin Date: 2008-02-04T13:26:07+09:00 Subject: Re: [QUIZ] Parsing JSON (#155) ------=_Part_4458_11886011.1202099173885 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Feb 3, 2008 9:45 PM, steve wrote: > > I guess my eyes missed the ".read" after the STDIN . The "STDIN" jumped > > out > > and I thought it took an IO-like object. I was able to just remove a > > couple > > lines of Steve's code and rename the class to get it to work with the > > tests > > (unit and random performance benchmark). It mismatches in both the unit > > tests and the performance benchmark, but I if I remove the self-checking > I > > was able to run the performance benchmark. It was only about 6800 > > chars/second which is near the bottom of the heap. Not sure how valid > > that > > is since the parser has problems though. > > > > Hey Eric, > > What do you mean it mismatches? Also what do you mean by self-checking? > It passes all the unit tests for me. > > I just found out why you probably had problems with my solution on the > benchmark. You need to call .value on the object returned by the parser > to > get the actual parsed json value. > > t = b.report("#{depth} #{l}") { tree2 = parser.parse(s) } > --> > t = b.report("#{depth} #{l}") { tree2 = parser.parse(s).value } > > - steve > Thanks Steve, That was it. I didn't make a wrapper class like I did for the other Treetop parsers. Your parser works without problems now. Also, I grabbed Eric I's and Clifford Heath's Treetop parsers and benchmarked them. Here's what I found: ch/s author/gem ---- ---------- - Pawel Radecki (RE, mismatch) 3214 Justin Ethier (RE lexer + parser, fixed number parsing) 4054 Eric Mahurin (Grammar0, no lexer, no parser generation) 4078 Eric I (Treetop, unicode broken) 6534 oksteev (Treetop, mismatches in benchmark) 8313 Clifford Heath (Treetop, had to remove handling of "\/") 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) ------=_Part_4458_11886011.1202099173885--