./bench.pl
+=head1 OPTIONS
+
+=item B<-c>, B<--cflags>=I<flags>
+
+Flags to pass to the C or C++ compiler.
+
+=item B<-i>, B<--iterations>=I<integer>
+
+Say how many times a single test of the bench must be run.
+
+=item B<-v>, B<--verbose>
+
+Raise the verbosity level. Currently only affects B<--help>.
+
=cut
use IO::File;
my $bison = $ENV{'BISON'} || '@abs_top_builddir@/tests/bison';
my $cc = $ENV{'CC'} || 'gcc';
my $cxx = $ENV{'CXX'} || 'g++';
+# Compiler flags (C or C++).
+my $cflags = '';
+# The number of times the parser is run for a bench.
+my $iterations = 50;
##################################################################
+=head1 DESCRIPTIONS
+
=head2 Functions
=over 4
| "1" "2" "3" "4" "5" END { $$ = 5; }
;
-C<$base> is the base name for the file to create (C<$base.y>).
+C<$base> is the base name for the file to create (F<$base.y>).
C<$max> is the number of such rules (here, 5). You may pass
additional Bison C<@directives>.
=item C<calc_input ($base, $max)>
-Generate the input file C<$base.input> for the calc parser. The input
+Generate the input file F<$base.input> for the calc parser. The input
is composed of two expressions. The first one is using left recursion
only and consumes no stack. The second one requires a deep stack.
These two expressions are repeated C<$max> times in the output file.
##################################################################
=item C<calc_grammar ($base, $max, @directives)>
-Generate a Bison file C<$base.y> for a calculator parser in C. Pass
+Generate a Bison file F<$base.y> for a calculator parser in C. Pass
the additional Bison C<@directives>. C<$max> is ignored, but left to
have the same interface as C<triangular_grammar>.
=item C<variant_grammar ($base, $max, @directives)>
-Generate a Bison file C<$base.y> that uses, or not, the Boost.Variants
+Generate a Bison file F<$base.y> that uses, or not, the Boost.Variants
depending on the C<@directives>.
=cut
// Prototype of the yylex function providing subsequent tokens.
static yy::parser::token_type yylex(yy::parser::semantic_type* yylval);
-#define STAGE_MAX $max
+#define STAGE_MAX ($max * 10)
#define USE_VARIANTS $variant
#if USE_VARIANTS
# define IF_VARIANTS(True, False) True
system ("$bison $base.y -o $base.c") == 0
or die;
- system ("$compiler -o $base -O3 -I /opt/local/include $base.c") == 0
+ system ("$compiler -o $base $cflags $base.c") == 0
or die;
}
Generate benches for C<$gram>. C<$gram> should be C<calc> or
C<triangle>. C<%bench> is a hash of the form:
- C<$name> => C<@directives>
+ $name => @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
print "$gram:\n";
# Run the benches.
- my $res = timethese (50, \%bench, 'nop');
+ my $res = timethese ($iterations, \%bench, 'nop');
# Output the result.
cmpthese ($res, 'nop');
}
############################################################################
-print STDERR "Using bison=$bison, cc=$cc, cxx=$cxx.\n";
+sub help ($)
+{
+ my ($verbose) = @_;
+ use Pod::Usage;
+ # See <URL:http://perldoc.perl.org/pod2man.html#NOTES>.
+ pod2usage( { -message => "Bench Bison parsers",
+ -exitval => 0,
+ -verbose => $verbose,
+ -output => \*STDOUT });
+}
+
+sub getopt ()
+{
+ use Getopt::Long;
+ my $verbose = 0;
+ %option = ("h|help" => sub { help ($verbose) },
+ "v|verbose" => sub { ++$verbose },
+ "c|cflags=s" => \$cflags,
+ "i|iterations=i" => \$iterations);
+ Getopt::Long::Configure ("bundling", "pass_through");
+ GetOptions (%option)
+ or exit 1;
+}
+
+######################################################################
+
+getopt;
+print STDERR "Using bison=$bison, cc=$cc, cxx=$cxx, cflags=$cflags.\n";
# bench_push_parser();
bench_variant_parser();