Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
new benchmark: json parsing without creating objects
- Loading branch information
Showing
3 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # JSON parsing copied from JSON::Tiny with changes to work in NQP | ||
| # and other very minor changes | ||
|
|
||
| grammar JSON::Tiny::Grammar { | ||
| token TOP { ^ \s* [ <object> | <array> ] \s* $ } | ||
| rule object { '{' ~ '}' <pairlist> } | ||
| rule pairlist { <?> <pair> * % \, } | ||
| rule pair { <?> <string> ':' <value> } | ||
| rule array { '[' ~ ']' <arraylist> } | ||
| rule arraylist { <?> <value>* % [ \, ] } | ||
|
|
||
| proto token value {*} | ||
| token value:sym<number> { | ||
| '-'? | ||
| [ 0 | <[1..9]> <[0..9]>* ] | ||
| [ \. <[0..9]>+ ]? | ||
| [ <[eE]> [\+|\-]? <[0..9]>+ ]? | ||
| } | ||
| token value:sym<true> { <sym> } | ||
| token value:sym<false> { <sym> } | ||
| token value:sym<null> { <sym> } | ||
| token value:sym<object> { <object> } | ||
| token value:sym<array> { <array> } | ||
| token value:sym<string> { <string> } | ||
|
|
||
| token string { | ||
| \" ~ \" ( <str> | \\ <str_escape> )* | ||
| } | ||
|
|
||
| token str { | ||
| <-["\\\t\n]>+ | ||
| } | ||
|
|
||
| token str_escape { | ||
| <["\\/bfnrt]> | u <xdigit>**4 | ||
| } | ||
| } | ||
|
|
||
| sub from-json($text) { | ||
| JSON::Tiny::Grammar.parse($text); | ||
| } | ||
|
|
||
| sub main($json-file, $count) { | ||
| my $json := slurp($json-file); | ||
|
|
||
| my int $i := 0; | ||
| while $i < $count { | ||
| my $data := from-json($json); | ||
| $i := $i + 1; | ||
| } | ||
| } | ||
|
|
||
| sub MAIN (*@args) { | ||
| @args.shift if @args == 3; | ||
| main(|@args); | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # JSON parsing copied from JSON::Tiny with very minor changes | ||
|
|
||
| grammar JSON::Tiny::Grammar { | ||
| token TOP { ^ \s* [ <object> | <array> ] \s* $ } | ||
| rule object { '{' ~ '}' <pairlist> } | ||
| rule pairlist { <?> <pair> * % \, } | ||
| rule pair { <?> <string> ':' <value> } | ||
| rule array { '[' ~ ']' <arraylist> } | ||
| rule arraylist { <?> <value>* % [ \, ] } | ||
|
|
||
| proto token value {*} | ||
| token value:sym<number> { | ||
| '-'? | ||
| [ 0 | <[1..9]> <[0..9]>* ] | ||
| [ \. <[0..9]>+ ]? | ||
| [ <[eE]> [\+|\-]? <[0..9]>+ ]? | ||
| } | ||
| token value:sym<true> { <sym> } | ||
| token value:sym<false> { <sym> } | ||
| token value:sym<null> { <sym> } | ||
| token value:sym<object> { <object> } | ||
| token value:sym<array> { <array> } | ||
| token value:sym<string> { <string> } | ||
|
|
||
| token string { | ||
| \" ~ \" ( <str> | \\ <str_escape> )* | ||
| } | ||
|
|
||
| token str { | ||
| <-["\\\t\n]>+ | ||
| } | ||
|
|
||
| token str_escape { | ||
| <["\\/bfnrt]> | u <xdigit>**4 | ||
| } | ||
| } | ||
|
|
||
| sub from-json($text) { | ||
| JSON::Tiny::Grammar.parse($text); | ||
| } | ||
|
|
||
| sub MAIN($json-file, $count) { | ||
| my $json := slurp($json-file); | ||
|
|
||
| for ^$count { | ||
| my $data := from-json($json); #OK | ||
| } | ||
| } |