my $char = $self->_peek_char();
which lead me to expect the module to be quite slow at what it does.
Luckily, parsing JSON is quite an easy task. Just checking it for validity is
even easier than that. So I quickly rolled a JSON parser that just checked
validity and didn't read the whole file into RAM at once.
So I built a 65MB file of JSON so I could compare:
> perl isJson.pl < file.json
Valid JSON.
Took 38s.
> perl loops.pl
okTook 446s.
So it looks like my version is over 10x faster.
[Update: Adding $jsonr->skip() inside the empty 'sub' as Loops suggests, makes the module run about 2x faster:
> perl skip.pl
okTook 235s.
or only about 1/6th as fast as my code.]
Then I added an error near the end of the file:
> perl loops.pl
panicTook 402s.
> perl isJson.pl < file.json
Invalid bare word (troo) at line 1020000, pos 8 (t)
Took 39s.
So you can see it also gives much better information about where the problem was.
|