Akron | aa229a2 | 2020-02-18 13:44:25 +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 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 = 'tei2korapxml'; |
| 29 | |
| 30 | my $f = dirname(__FILE__); |
| 31 | my $script = rel2abs(catfile($f, '..', 'script', $SCRIPT_NAME)); |
| 32 | |
| 33 | # Load example file |
| 34 | my $file = rel2abs(catfile($f, '..', 't', 'data', 'goe_sample.i5.xml')); |
| 35 | |
| 36 | # Create a new benchmark object |
| 37 | my $bench = Dumbbench->new( |
| 38 | verbosity => 0 |
| 39 | ); |
| 40 | |
| 41 | # Add benchmark instances |
| 42 | $bench->add_instances( |
| 43 | Dumbbench::Instance::PerlSub->new( |
| 44 | name => 'SimpleConversion', |
| 45 | code => sub { |
| 46 | `cat '$file' | perl '$script' > /dev/null 2>&1` |
| 47 | } |
| 48 | ) |
| 49 | ); |
| 50 | |
| 51 | # Run benchmarks |
| 52 | $bench->run; |
| 53 | |
| 54 | # Output in a single row |
| 55 | if ($columns) { |
| 56 | unless ($no_header) { |
| 57 | print join("\t", map { $_->name } $bench->instances), "\n"; |
| 58 | }; |
| 59 | print join("\t", map { $_->result->raw_number } $bench->instances), "\n"; |
| 60 | exit(0); |
| 61 | }; |
| 62 | |
| 63 | # Output simple timings for comparation |
| 64 | foreach my $inst ($bench->instances) { |
| 65 | unless ($no_header) { |
| 66 | print $inst->name, ': '; |
| 67 | }; |
| 68 | print $inst->result->raw_number, "\n"; |
| 69 | }; |
| 70 | |
| 71 | exit(0); |
| 72 | |
| 73 | __END__ |