blob: 35c0c6542f7c30fa93c589b1b800c3c0dff8c43a [file] [log] [blame]
Akronaa229a22020-02-18 13:44:25 +01001#!/usr/bin/env perl
2use strict;
3use warnings;
4use Dumbbench;
5use File::Basename 'dirname';
6use File::Spec::Functions qw/catfile rel2abs/;
7use File::Temp ':POSIX';
8use FindBin;
9use Getopt::Long;
10
11BEGIN {
12 unshift @INC, "$FindBin::Bin/../lib";
13};
14
Akron4f67cd42020-07-02 12:27:58 +020015use KorAP::XML::TEI;
16
Akronaa229a22020-02-18 13:44:25 +010017my $columns = 0;
18my $no_header = 0;
19GetOptions(
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
30our $SCRIPT_NAME = 'tei2korapxml';
31
32my $f = dirname(__FILE__);
33my $script = rel2abs(catfile($f, '..', 'script', $SCRIPT_NAME));
34
35# Load example file
36my $file = rel2abs(catfile($f, '..', 't', 'data', 'goe_sample.i5.xml'));
37
38# Create a new benchmark object
39my $bench = Dumbbench->new(
40 verbosity => 0
41);
42
Akron4f67cd42020-07-02 12:27:58 +020043my $result;
44
Akronaa229a22020-02-18 13:44:25 +010045# 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 }
Akron4f67cd42020-07-02 12:27:58 +020052 ),
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 ),
Akronaa229a22020-02-18 13:44:25 +010064);
65
66# Run benchmarks
67$bench->run;
68
69# Output in a single row
70if ($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
79foreach my $inst ($bench->instances) {
80 unless ($no_header) {
81 print $inst->name, ': ';
82 };
83 print $inst->result->raw_number, "\n";
84};
85
86exit(0);
87
88__END__