blob: ddd17a2a7e542a9853eacb0dff8b06d8df0422a3 [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/;
Akron2d547bc2020-07-04 10:34:35 +02007use File::Temp 'tempfile';
Akronaa229a22020-02-18 13:44:25 +01008use 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;
Akron2d547bc2020-07-04 10:34:35 +020044my ($fh, $filename) = tempfile();
45
46print $fh <<'HTML';
47mehrzeiliger
48Kommentar
49 --><!-- Versuch
50-->ist <!-- a --><!-- b --> ein Test
51HTML
52
Akron4f67cd42020-07-02 12:27:58 +020053
Akronaa229a22020-02-18 13:44:25 +010054# Add benchmark instances
55$bench->add_instances(
56 Dumbbench::Instance::PerlSub->new(
57 name => 'SimpleConversion',
58 code => sub {
59 `cat '$file' | perl '$script' > /dev/null 2>&1`
60 }
Akron4f67cd42020-07-02 12:27:58 +020061 ),
62 Dumbbench::Instance::PerlSub->new(
63 name => 'delHTMLcom',
64 code => sub {
65 for (1..100_000) {
66 $result = KorAP::XML::TEI::delHTMLcom(
67 \*STDIN,
68 "This <!-- comment --> is a test " . $_
69 );
70 };
71 }
72 ),
Akron2d547bc2020-07-04 10:34:35 +020073 Dumbbench::Instance::PerlSub->new(
74 name => 'delHTMLcom-long',
75 code => sub {
76 for (1..10_000) {
77 $result = KorAP::XML::TEI::delHTMLcom(
78 $fh,
79 "This <!--" . $_
80 );
81 seek($fh, 0, 0);
82 };
83 }
84 ),
Akronaa229a22020-02-18 13:44:25 +010085);
86
87# Run benchmarks
88$bench->run;
89
Akron2d547bc2020-07-04 10:34:35 +020090# Clean up
91close($fh);
92
Akronaa229a22020-02-18 13:44:25 +010093# Output in a single row
94if ($columns) {
95 unless ($no_header) {
96 print join("\t", map { $_->name } $bench->instances), "\n";
97 };
98 print join("\t", map { $_->result->raw_number } $bench->instances), "\n";
99 exit(0);
100};
101
102# Output simple timings for comparation
103foreach my $inst ($bench->instances) {
104 unless ($no_header) {
105 print $inst->name, ': ';
106 };
107 print $inst->result->raw_number, "\n";
108};
109
110exit(0);
111
112__END__