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 | |
Akron | 4f67cd4 | 2020-07-02 12:27:58 +0200 | [diff] [blame^] | 15 | use KorAP::XML::TEI; |
| 16 | |
Akron | aa229a2 | 2020-02-18 13:44:25 +0100 | [diff] [blame] | 17 | my $columns = 0; |
| 18 | my $no_header = 0; |
| 19 | GetOptions( |
| 20 | 'columns|c' => \$columns, |
| 21 | 'no-header|n' => \$no_header, |
| 22 | 'help|h' => sub { |
| 23 | print "--columns|-c Print instances in columns\n"; |
| 24 | print "--no-header|-n Dismiss benchmark names\n"; |
| 25 | print "--help|-h Print this page\n\n"; |
| 26 | exit(0); |
| 27 | } |
| 28 | ); |
| 29 | |
| 30 | our $SCRIPT_NAME = 'tei2korapxml'; |
| 31 | |
| 32 | my $f = dirname(__FILE__); |
| 33 | my $script = rel2abs(catfile($f, '..', 'script', $SCRIPT_NAME)); |
| 34 | |
| 35 | # Load example file |
| 36 | my $file = rel2abs(catfile($f, '..', 't', 'data', 'goe_sample.i5.xml')); |
| 37 | |
| 38 | # Create a new benchmark object |
| 39 | my $bench = Dumbbench->new( |
| 40 | verbosity => 0 |
| 41 | ); |
| 42 | |
Akron | 4f67cd4 | 2020-07-02 12:27:58 +0200 | [diff] [blame^] | 43 | my $result; |
| 44 | |
Akron | aa229a2 | 2020-02-18 13:44:25 +0100 | [diff] [blame] | 45 | # Add benchmark instances |
| 46 | $bench->add_instances( |
| 47 | Dumbbench::Instance::PerlSub->new( |
| 48 | name => 'SimpleConversion', |
| 49 | code => sub { |
| 50 | `cat '$file' | perl '$script' > /dev/null 2>&1` |
| 51 | } |
Akron | 4f67cd4 | 2020-07-02 12:27:58 +0200 | [diff] [blame^] | 52 | ), |
| 53 | Dumbbench::Instance::PerlSub->new( |
| 54 | name => 'delHTMLcom', |
| 55 | code => sub { |
| 56 | for (1..100_000) { |
| 57 | $result = KorAP::XML::TEI::delHTMLcom( |
| 58 | \*STDIN, |
| 59 | "This <!-- comment --> is a test " . $_ |
| 60 | ); |
| 61 | }; |
| 62 | } |
| 63 | ), |
Akron | aa229a2 | 2020-02-18 13:44:25 +0100 | [diff] [blame] | 64 | ); |
| 65 | |
| 66 | # Run benchmarks |
| 67 | $bench->run; |
| 68 | |
| 69 | # Output in a single row |
| 70 | if ($columns) { |
| 71 | unless ($no_header) { |
| 72 | print join("\t", map { $_->name } $bench->instances), "\n"; |
| 73 | }; |
| 74 | print join("\t", map { $_->result->raw_number } $bench->instances), "\n"; |
| 75 | exit(0); |
| 76 | }; |
| 77 | |
| 78 | # Output simple timings for comparation |
| 79 | foreach my $inst ($bench->instances) { |
| 80 | unless ($no_header) { |
| 81 | print $inst->name, ': '; |
| 82 | }; |
| 83 | print $inst->result->raw_number, "\n"; |
| 84 | }; |
| 85 | |
| 86 | exit(0); |
| 87 | |
| 88 | __END__ |