Akron | 6e886f7 | 2020-02-19 07:42:32 +0100 | [diff] [blame] | 1 | #!/usr/bin/env perl |
| 2 | use strict; |
| 3 | use warnings; |
| 4 | use Dumbbench; |
| 5 | use File::Basename 'dirname'; |
| 6 | use File::Spec::Functions qw/catfile catdir rel2abs/; |
| 7 | use File::Temp ':POSIX'; |
| 8 | use FindBin; |
| 9 | use Getopt::Long; |
| 10 | |
| 11 | BEGIN { |
| 12 | unshift @INC, "$FindBin::Bin/../lib"; |
| 13 | }; |
| 14 | |
| 15 | my $columns = 0; |
| 16 | my $no_header = 0; |
| 17 | GetOptions( |
| 18 | 'columns|c' => \$columns, |
| 19 | 'no-header|n' => \$no_header, |
| 20 | 'help|h' => sub { |
| 21 | print "--columns|-c Print instances in columns\n"; |
| 22 | print "--no-header|-n Dismiss benchmark names\n"; |
| 23 | print "--help|-h Print this page\n\n"; |
| 24 | exit(0); |
| 25 | } |
| 26 | ); |
| 27 | |
| 28 | our $SCRIPT_NAME = 'korapxml2krill'; |
| 29 | |
| 30 | my $f = dirname(__FILE__); |
| 31 | my $script = rel2abs(catfile($f, '..', 'script', $SCRIPT_NAME)); |
| 32 | |
| 33 | |
| 34 | # begin instance 1 setup |
| 35 | # Load example file |
| 36 | my $input = rel2abs(catdir($f, '..', 't', 'annotation', 'corpus', 'doc', '0001')); |
| 37 | my $output = tmpnam(); |
| 38 | my $cache = tmpnam(); |
| 39 | # end instance 1 |
| 40 | |
| 41 | # Create a new benchmark object |
| 42 | my $bench = Dumbbench->new( |
| 43 | verbosity => 0 |
| 44 | ); |
| 45 | |
| 46 | # Add benchmark instances |
| 47 | $bench->add_instances( |
| 48 | Dumbbench::Instance::PerlSub->new( |
Akron | 414ec95 | 2020-08-03 15:48:43 +0200 | [diff] [blame^] | 49 | name => 'Script-ExampleRun-1', |
Akron | 6e886f7 | 2020-02-19 07:42:32 +0100 | [diff] [blame] | 50 | code => sub { |
| 51 | my $cmd = join( |
| 52 | ' ', |
| 53 | 'perl', $script, |
| 54 | '--input' => $input, |
| 55 | '--output' => $output, |
| 56 | '--cache' => $cache, |
| 57 | '-k' => '0.03', |
| 58 | '-t' => 'OpenNLP#Tokens', |
| 59 | '-l' => 'ERROR', |
| 60 | '>' => '/dev/null' |
| 61 | ); |
| 62 | `$cmd`; |
| 63 | } |
| 64 | ) |
| 65 | ); |
| 66 | |
| 67 | # Run benchmarks |
| 68 | $bench->run; |
| 69 | |
| 70 | # Output in a single row |
| 71 | if ($columns) { |
| 72 | unless ($no_header) { |
| 73 | print join("\t", map { $_->name } $bench->instances), "\n"; |
| 74 | }; |
Akron | 9711ed3 | 2020-02-19 08:10:29 +0100 | [diff] [blame] | 75 | print join("\t", map { $_->result->raw_number } $bench->instances), "\n"; |
Akron | 6e886f7 | 2020-02-19 07:42:32 +0100 | [diff] [blame] | 76 | exit(0); |
| 77 | }; |
| 78 | |
| 79 | # Output simple timings for comparation |
| 80 | foreach my $inst ($bench->instances) { |
| 81 | unless ($no_header) { |
| 82 | print $inst->name, ': '; |
| 83 | }; |
Akron | 9711ed3 | 2020-02-19 08:10:29 +0100 | [diff] [blame] | 84 | print $inst->result->raw_number, "\n"; |
Akron | 6e886f7 | 2020-02-19 07:42:32 +0100 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | exit(0); |