bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Improve genericity of bench.pl.


From: Akim Demaille
Subject: [PATCH] Improve genericity of bench.pl.
Date: Mon, 03 Nov 2008 21:00:26 -0000

        * etc/bench.pl.in (&bench_grammar): Take the set of benches as
        argument.
        (&bench_push_parser): New.
        Call it.
---
 ChangeLog       |    8 ++++++++
 etc/bench.pl.in |   52 ++++++++++++++++++++++++++++++++++++++--------------
 2 files changed, 46 insertions(+), 14 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2c0369b..c15a154 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2008-11-03  Akim Demaille  <address@hidden>
 
+       Improve genericity of bench.pl.
+       * etc/bench.pl.in (&bench_grammar): Take the set of benches as
+       argument.
+       (&bench_push_parser): New.
+       Call it.
+
+2008-11-03  Akim Demaille  <address@hidden>
+
        Add documentation to bench.pl.
        * etc/bench.pl.in: Comment changes.
 
diff --git a/etc/bench.pl.in b/etc/bench.pl.in
index 77d9975..87bb53b 100755
--- a/etc/bench.pl.in
+++ b/etc/bench.pl.in
@@ -398,28 +398,29 @@ sub compile ($)
     or die;
 }
 
-=item C<bench_grammar ($gram)>
+=item C<bench_grammar ($gram, %bench)>
 
 Generate benches for C<$gram>.  C<$gram> should be C<calc> or
-C<triangle>.
+C<triangle>.  C<%bench> is a hash of the form:
+
+  C<$name> => C<$directives>
+
+where C<$name> is the name of the bench, and C<$directives> are the
+Bison directive to use for this bench.  All the benches are compared
+against each other, repeated 50 times.
 
 =cut
 
-sub bench_grammar ($)
+sub bench_grammar ($%)
 {
-  my ($gram) = @_;
-  my %test =
-    (
-     "pull-impure" => '',
-     "pull-pure" => '%define api.pure',
-     "push-impure" => '%define api.push_pull "both"',
-     "push-pure" => '%define api.push_pull "both" %define api.pure',
-    );
+  my ($gram, %test) = @_;
 
+  # Set up the benches as expected by timethese.
   my %bench;
   while (my ($name, $directives) = each %test)
     {
       print STDERR "$name\n";
+      # Call the Bison input file generator.
       my $generator = "$gram" . "_grammar";
       &$generator ($name, 200, $directives);
       compile ($name);
@@ -427,13 +428,36 @@ sub bench_grammar ($)
     }
 
   print "$gram:\n";
+  # Run the benches.
   my $res = timethese (50, \%bench, 'nop');
+  # Output the result.
   cmpthese ($res, 'nop');
 }
 
-print STDERR "Using $bison, $cc.\n";
-calc_input ('calc', 200);
-bench_grammar ('calc');
+
+=item C<bench_push_parser ()>
+
+Bench the C push parser against the pull parser, pure and impure
+interfaces.
+
+=cut
+
+sub bench_push_parser ()
+{
+  print STDERR "Using $bison, $cc.\n";
+  calc_input ('calc', 200);
+  bench_grammar
+    ('calc',
+     (
+      "pull-impure" => '',
+      "pull-pure" => '%define api.pure',
+      "push-impure" => '%define api.push_pull "both"',
+      "push-pure" => '%define api.push_pull "both" %define api.pure',
+     )
+    );
+}
+
+bench_push_parser();
 
 ### Setup "GNU" style for perl-mode and cperl-mode.
 ## Local Variables:
-- 
1.6.0.2.588.g3102





reply via email to

[Prev in Thread] Current Thread [Next in Thread]