This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
add Porting/bench.pl
[perl5.git] / t / perf / benchmarks.t
CommitLineData
24fb648d
DM
1#!./perl
2#
3# Execute the various code snippets in t/perf/benchmarks
4# to ensure that they are all syntactically correct
5
6BEGIN {
7 chdir 't';
8 require './test.pl';
9 @INC = ('.', '../lib');
10}
11
12use warnings;
13use strict;
14
15
16my $file = 'perf/benchmarks';
9e7973fa 17my $benchmark_array = do $file;
24fb648d
DM
18die $@ if $@;
19die "$! while trying to read '$file'" if $!;
9e7973fa
DM
20die "'$file' did not return an array ref\n"
21 unless ref $benchmark_array eq 'ARRAY';
22
23die "Not an even number of key value pairs in '$file'\n"
24 if @$benchmark_array % 2;
25
26my %benchmarks;
27while (@$benchmark_array) {
28 my $key = shift @$benchmark_array;
29 my $hash = shift @$benchmark_array;
30 die "Duplicate key '$key' in '$file'\n" if exists $benchmarks{$key};
31 $benchmarks{$key} = $hash;
32}
24fb648d 33
9e7973fa 34plan keys(%benchmarks) * 3;
24fb648d
DM
35
36
37# check the hash of hashes is minimally consistent in format
38
9e7973fa
DM
39for my $token (sort keys %benchmarks) {
40 like($token, qr/^[a-zA-Z](\w|::)+$/a, "legal token: $token");
41 my $keys = join('-', sort keys %{$benchmarks{$token}});
24fb648d
DM
42 is($keys, 'code-desc-setup', "legal keys: $token");
43}
44
45# check that each bit of code compiles and runs
46
9e7973fa
DM
47for my $token (sort keys %benchmarks) {
48 my $b = $benchmarks{$token};
24fb648d 49 my $code = "package $token; $b->{setup}; for (1..1) { $b->{code} } 1;";
9e7973fa
DM
50 no warnings;
51 no strict;
24fb648d
DM
52 ok(eval $code, "running $token")
53 or do {
54 diag("code:");
55 diag($code);
56 diag("gave:");
57 diag($@);
58 }
59}
60
61