Skip to content

Instantly share code, notes, and snippets.

Created August 24, 2016 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/d174b1677499edc6838a05ebf1b1fb9c to your computer and use it in GitHub Desktop.
Save anonymous/d174b1677499edc6838a05ebf1b1fb9c to your computer and use it in GitHub Desktop.
diff --git a/src/core/Rakudo/Internals/JSON.pm b/src/core/Rakudo/Internals/JSON.pm
index d8ae999..eaa9b69 100644
--- a/src/core/Rakudo/Internals/JSON.pm
+++ b/src/core/Rakudo/Internals/JSON.pm
@@ -6,6 +6,9 @@ my class JSONException is Exception {
}
}
+my $total_time = 0e0;
+my %cache;
+
my class Rakudo::Internals::JSON {
my class JSONPrettyActions {
method TOP($/) {
@@ -126,9 +129,21 @@ my class Rakudo::Internals::JSON {
}
method from-json($text) {
+ note $text.perl;
+ if %cache{$text}:exists {
+ note "already in cache."
+ }
+ else {
+ %cache{$text} = 1;
+ }
+ my $start = now;
my $a = JSONPrettyActions.new();
my $o = JSONPrettyGrammar.parse($text, :actions($a));
JSONException.new(:$text).throw unless $o;
+ my $took = now - $start;
+ note "--" if $total_time == 0e0;
+ $total_time = $total_time + $took;
+ note "json parse took { now - $start }s - $total_time";
$o.ast;
}
method to-json(|c) { to-json(|c) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment