Make benches in a sub dirs.

* etc/bench.pl.in ($dir): New.
	Use it.
	Check the use of constructors with an argument.
	(bench_variant_parser): Fix.
This commit is contained in:
Akim Demaille
2008-08-07 21:23:41 +02:00
parent db65ca1f12
commit c85be41a07
2 changed files with 78 additions and 31 deletions

View File

@@ -1,3 +1,11 @@
2008-11-09 Akim Demaille <demaille@gostai.com>
Make benches in a sub dirs.
* etc/bench.pl.in ($dir): New.
Use it.
Check the use of constructors with an argument.
(bench_variant_parser): Fix.
2008-11-09 Akim Demaille <demaille@gostai.com> 2008-11-09 Akim Demaille <demaille@gostai.com>
fix eof condition fix eof condition

View File

@@ -598,12 +598,19 @@ $directives
static yy::parser::token_type yylex(yy::parser::semantic_type* yylval); static yy::parser::token_type yylex(yy::parser::semantic_type* yylval);
#define STAGE_MAX ($max * 10) // max = $max #define STAGE_MAX ($max * 10) // max = $max
#define USE_VARIANTS $variant #define USE_VARIANTS $variant
#if USE_VARIANTS #if USE_VARIANTS
# define IF_VARIANTS(True, False) True # define IF_VARIANTS(True, False) True
#else #else
# define IF_VARIANTS(True, False) False # define IF_VARIANTS(True, False) False
#endif #endif
#ifdef ONE_STAGE_BUILD
# define IF_ONE_STAGE_BUILD(True, False) True
#else
# define IF_ONE_STAGE_BUILD(True, False) False
#endif
} }
EOF EOF
@@ -675,12 +682,28 @@ yylex(yy::parser::semantic_type* yylval)
return yy::parser::token::END_OF_FILE; return yy::parser::token::END_OF_FILE;
else if (stage % 2) else if (stage % 2)
{ {
IF_VARIANTS(yylval->build<int>(), yylval->ival) = stage; #if USE_VARIANTS
# ifdef ONE_STAGE_BUILD
yylval->build(stage);
# else
yylval->build<int>() = stage;
# endif
#else
yylval->ival = stage;
#endif
return yy::parser::token::NUMBER; return yy::parser::token::NUMBER;
} }
else else
{ {
IF_VARIANTS(yylval->build<std::string>() =, yylval->sval = new) std::string("A string."); #if USE_VARIANTS
# ifdef ONE_STAGE_BUILD
yylval->build(std::string("A string."));
# else
yylval->build<std::string>() = std::string("A string.");
# endif
#else
yylval->sval = new std::string("A string.");
#endif
return yy::parser::token::TEXT; return yy::parser::token::TEXT;
} }
abort(); abort();
@@ -717,7 +740,7 @@ Generate F<$base.y> by calling C<&generate_grammar_$name>.
sub generate_grammar ($$@) sub generate_grammar ($$@)
{ {
my ($name, $base, @directive) = @_; my ($name, $base, @directive) = @_;
verbose 2, "Generating $base.y\n"; verbose 3, "Generating $base.y\n";
my %generator = my %generator =
( (
"calc" => \&generate_grammar_calc, "calc" => \&generate_grammar_calc,
@@ -738,7 +761,7 @@ Run, possibly verbosely, the shell C<$command>.
sub run ($) sub run ($)
{ {
my ($command) = @_; my ($command) = @_;
verbose 2, "$command\n"; verbose 3, "$command\n";
system ("$command") == 0 system ("$command") == 0
or die "$command failed"; or die "$command failed";
} }
@@ -812,7 +835,7 @@ sub bench ($@)
# shows only wallclock and the two children times. 'auto' (the # shows only wallclock and the two children times. 'auto' (the
# default) will act as 'all' unless the children times are both # default) will act as 'all' unless the children times are both
# zero, in which case it acts as 'noc'. 'none' prevents output. # zero, in which case it acts as 'noc'. 'none' prevents output.
verbose 2, "Running the benches for $grammar\n"; verbose 3, "Running the benches for $grammar\n";
my $res = timethese ($iterations, \%bench, 'nop'); my $res = timethese ($iterations, \%bench, 'nop');
# Output the speed result. # Output the speed result.
@@ -863,14 +886,17 @@ Bench the C++ lalr1.cc parser using Boost.Variants or %union.
sub bench_variant_parser () sub bench_variant_parser ()
{ {
bench ('variant', bench ('list',
('%skeleton "lalr1.cc"', ('%skeleton "lalr1.cc"',
'&', '&',
'[', '%debug', ']', '[', '%debug', ']',
'&', '&',
'[', '%define variant', ']', '[', '%define variant',
'&', '&',
'[', "%code {\n#define VARIANT_DESTROY\n}", ']' '[', "%code {\n#define VARIANT_DESTROY\n}", ']',
'&',
'[', "%code {\n#define ONE_STAGE_BUILD\n}", ']',
']'
)); ));
} }
@@ -915,7 +941,7 @@ my @token;
sub parse (@) sub parse (@)
{ {
@token = @_; @token = @_;
verbose 2, "Parsing: @token\n"; verbose 3, "Parsing: @token\n";
my @res = parse_expr (); my @res = parse_expr ();
die "expected end of directives, unexpected: @token" die "expected end of directives, unexpected: @token"
if defined $token[0]; if defined $token[0];
@@ -1002,36 +1028,49 @@ sub getopt ()
Getopt::Long::Configure ("bundling", "pass_through"); Getopt::Long::Configure ("bundling", "pass_through");
GetOptions (%option) GetOptions (%option)
or exit 1; or exit 1;
# Support -b: predefined benches.
my %bench =
(
"fusion" => \&bench_fusion_parser,
"push" => \&bench_push_parser,
"variant" => \&bench_variant_parser,
);
if (defined $bench)
{
die "invalid argument for --bench: $bench"
unless defined $bench{$bench};
&{$bench{$bench}}();
exit 0;
}
} }
###################################################################### ######################################################################
getopt; getopt;
# Create the directory we work in.
my $count = 1;
++$count
while -d "bench-$count";
my $dir = "bench-$count";
mkdir $dir
or die "cannot create $dir";
chdir $dir
or die "cannot chdir $dir";
verbose 1, "Benching in $dir.\n";
verbose 1, "Using bison=$bison.\n"; verbose 1, "Using bison=$bison.\n";
verbose 1, "Using cc=$cc.\n"; verbose 2, "Using cc=$cc.\n";
verbose 1, "Using cxx=$cxx.\n"; verbose 2, "Using cxx=$cxx.\n";
verbose 1, "Using cflags=$cflags.\n"; verbose 2, "Using cflags=$cflags.\n";
verbose 2, "Grammar: $grammar\n"; verbose 2, "Grammar: $grammar\n";
# Launch the bench marking.
bench ($grammar, @ARGV);
# Support -b: predefined benches.
my %bench =
(
"fusion" => \&bench_fusion_parser,
"push" => \&bench_push_parser,
"variant" => \&bench_variant_parser,
);
if (defined $bench)
{
die "invalid argument for --bench: $bench"
unless defined $bench{$bench};
&{$bench{$bench}}();
exit 0;
}
else
{
# Launch the bench marking.
bench ($grammar, @ARGV);
}
### Setup "GNU" style for perl-mode and cperl-mode. ### Setup "GNU" style for perl-mode and cperl-mode.
## Local Variables: ## Local Variables: