blob: 027901e57a6459301fc49854b436067985d811e9 [file] [log] [blame]
Akron43cc5c92022-03-02 14:25:30 +01001#!/usr/bin/env perl
2use strict;
3use warnings;
4use Benchmark qw!:hireswallclock :all!;
5use Data::Dumper;
6use POSIX 'round';
7
Akron9127d4f2022-03-11 10:54:46 +01008our @ARGV;
9
10# The first parameter is the batch size (how often is the text concatenated)
11# The second parameter is the number of iterations.
12
Akron43cc5c92022-03-02 14:25:30 +010013my $FILE = 'effi-1x-utf8.txt';
Akron43cc5c92022-03-02 14:25:30 +010014system 'gzip -dkf ./corpus/' . $FILE . '.gz';
Akron43cc5c92022-03-02 14:25:30 +010015my $iter = 1;
16
Akron9127d4f2022-03-11 10:54:46 +010017if ($ARGV[0]) {
18 my $number = $ARGV[0] + 0;
19 my $out = 'effi-'.$number.'x-utf8.txt';
20 for (my $i = 1; $i <= $number; $i++) {
21 system 'cat ./corpus/' . $FILE . ' >> ./corpus/' . $out;
22 };
23 $FILE = $out;
24};
25
26if ($ARGV[1]) {
27 $iter = $ARGV[1] + 0;
28};
29
Akron43cc5c92022-03-02 14:25:30 +010030# Result of wc -w
31my $effi_wc = `wc -w ./corpus/$FILE`;
32$effi_wc =~ s/^(\d+)\s.*$/$1/;
33
34
35my $models = {
36 'wc' => sub {
37 system 'wc -w ./corpus/'.$FILE.' > /dev/null';
38 },
39 'SoMaJo' => sub {
40 system 'somajo-tokenizer ./corpus/'.$FILE.' --split_sentences > /dev/null';
41 },
42 'SoMaJo_p2' => sub {
43 system 'somajo-tokenizer ./corpus/'.$FILE.' --parallel=2 --split_sentences > /dev/null';
44 },
Akron9127d4f2022-03-11 10:54:46 +010045 'SoMaJo_p4' => sub {
46 system 'somajo-tokenizer ./corpus/'.$FILE.' --parallel=4 --split_sentences > /dev/null';
47 },
48 'SoMaJo_p8' => sub {
49 system 'somajo-tokenizer ./corpus/'.$FILE.' --parallel=8 --split_sentences > /dev/null';
50 },
Akron43cc5c92022-03-02 14:25:30 +010051 'Datok_matok' => sub {
52 system 'cat ./corpus/'.$FILE.' | ./Datok/datok tokenize -t ./Datok/testdata/tokenizer.matok - > /dev/null'
53 },
54 'Datok_datok' => sub {
55 system 'cat ./corpus/'.$FILE.' | ./Datok/datok tokenize -t ./Datok/testdata/tokenizer.datok - > /dev/null'
56 },
57 'OpenNLP_Simple' => sub {
58 system 'cat ./corpus/'.$FILE.' | ./opennlp/bin/opennlp SimpleTokenizer > /dev/null';
59 },
60 'OpenNLP_Tokenizer_de-ud-gsd' => sub {
61 system 'cat ./corpus/'.$FILE.' | ./opennlp/bin/opennlp TokenizerME ./opennlp/models/opennlp-de-ud-gsd-tokens-1.0-1.9.3.bin > /dev/null';
62 },
63 'OpenNLP_Sentence_de-ud-gsd' => sub {
64 system 'cat ./corpus/'.$FILE.' | ./opennlp/bin/opennlp SentenceDetector ./opennlp/models/opennlp-de-ud-gsd-sentence-1.0-1.9.3.bin > /dev/null';
65 },
66 'TreeTagger' => sub {
67 system 'cat ./corpus/'.$FILE.' | perl ./treetagger/cmd/utf8-tokenize.perl -a ./treetagger/lib/german-abbreviations > /dev/null';
68 },
69 'deep-eos_bi-lstm-de' => sub {
70 system 'python3 ./deep-eos/main.py --input-file ./corpus/'.$FILE.' --model-filename ./deep-eos/bi-lstm-de.model --vocab-filename ./deep-eos/bi-lstm-de.vocab --eos-marker "§" tag > /dev/null';
71 },
72 'deep-eos_cnn-de' => sub {
73 system 'python3 ./deep-eos/main.py --input-file ./corpus/'.$FILE.' --model-filename ./deep-eos/cnn-de.model --vocab-filename ./deep-eos/cnn-de.vocab --eos-marker "§" tag > /dev/null';
74 },
75 'deep-eos_lstm-de' => sub {
76 system 'python3 ./deep-eos/main.py --input-file ./corpus/'.$FILE.' --model-filename ./deep-eos/lstm-de.model --vocab-filename ./deep-eos/lstm-de.vocab --eos-marker "§" tag > /dev/null';
77 },
78 'JTok' => sub {
79 chdir '/euralex/JTok/bin';
80 system 'sh tokenize ../../corpus/'.$FILE.' de > /dev/null';
81 chdir '/euralex';
82 },
83 'KorAP-Tokenizer' => sub {
84 system 'cat ./corpus/'.$FILE.' | java -jar ./KorAP-Tokenizer/KorAP-Tokenizer.jar -l de -s > /dev/null'
85 },
86 Syntok_tokenizer => sub {
87 system 'python3 -m syntok.tokenizer ./corpus/'.$FILE.' > /dev/null';
88 },
89 Syntok_segmenter => sub {
90 system 'python3 -m syntok.segmenter ./corpus/'.$FILE.' > /dev/null';
91 },
92 Waste => sub {
Akroneb590da2022-03-02 18:31:34 +010093 system 'cat ./corpus/'.$FILE.' | waste -N -v0 --rcfile=./Waste/waste.rc > /dev/null';
Akron43cc5c92022-03-02 14:25:30 +010094 },
95 nnsplit => sub {
96 system './nnsplit/nnsplit_bench ./corpus/'.$FILE.' > /dev/null'
97 },
98 elephant => sub {
99 system './elephant-wrapper/bin/tokenize.sh -i ./corpus/'.$FILE.' UD_German > /dev/null'
100 },
101 SpaCy => sub {
102 system 'python3 ./spacy/spacy_tok.py ./corpus/'.$FILE.' > /dev/null'
Akronc2616422022-03-07 09:19:38 +0100103 },
104 Stanford => sub {
105 system 'CLASSPATH=/euralex/stanford-corenlp-4.4.0/* java edu.stanford.nlp.pipeline.StanfordCoreNLP ' .
106 '-props german -annotators tokenize,ssplit,mwt -tokenize.language=german -file ./corpus/' . $FILE
107 },
Akron9127d4f2022-03-11 10:54:46 +0100108 Stanford_t2 => sub {
109 system 'CLASSPATH=/euralex/stanford-corenlp-4.4.0/* java edu.stanford.nlp.pipeline.StanfordCoreNLP ' .
110 '-props german -annotators tokenize,ssplit,mwt -tokenize.language=german -threads=2 -file ./corpus/' . $FILE
111 },
Akronc2616422022-03-07 09:19:38 +0100112 Stanford_t4 => sub {
113 system 'CLASSPATH=/euralex/stanford-corenlp-4.4.0/* java edu.stanford.nlp.pipeline.StanfordCoreNLP ' .
114 '-props german -annotators tokenize,ssplit,mwt -tokenize.language=german -threads=4 -file ./corpus/' . $FILE
Akron9127d4f2022-03-11 10:54:46 +0100115 },
116 Stanford_t8 => sub {
117 system 'CLASSPATH=/euralex/stanford-corenlp-4.4.0/* java edu.stanford.nlp.pipeline.StanfordCoreNLP ' .
118 '-props german -annotators tokenize,ssplit,mwt -tokenize.language=german -threads=8 -file ./corpus/' . $FILE
119 }
Akron43cc5c92022-03-02 14:25:30 +0100120};
121
122#delete $models->{'SoMaJo'};
123#delete $models->{'SoMaJo_p2'};
Akron9127d4f2022-03-11 10:54:46 +0100124#delete $models->{'SoMaJo_p4'};
125#delete $models->{'SoMaJo_p8'};
Akron43cc5c92022-03-02 14:25:30 +0100126#delete $models->{'Datok_matok'};
127#delete $models->{'Datok_datok'};
128#delete $models->{'OpenNLP_Simple'};
129#delete $models->{'OpenNLP_Tokenizer_de-ud-gsd'};
130#delete $models->{'OpenNLP_Sentence_de-ud-gsd'};
131#delete $models->{'TreeTagger'};
132#delete $models->{'deep-eos_bi-lstm-de'};
133#delete $models->{'deep-eos_cnn-de'};
134#delete $models->{'deep-eos_lstm-de'};
135#delete $models->{'JTok'};
136#delete $models->{'KorAP-Tokenizer'};
137#delete $models->{'Syntok_tokenizer'};
138#delete $models->{'Syntok_segmenter'};
139#delete $models->{'Waste'};
140#delete $models->{'nnsplit'};
141#delete $models->{'elephant'};
142#delete $models->{'SpaCy'};
Akronc2616422022-03-07 09:19:38 +0100143#delete $models->{'Stanford'};
Akron9127d4f2022-03-11 10:54:46 +0100144#delete $models->{'Stanford_t2'};
Akronc2616422022-03-07 09:19:38 +0100145#delete $models->{'Stanford_t4'};
Akron9127d4f2022-03-11 10:54:46 +0100146#delete $models->{'Stanford_t8'};
Akron43cc5c92022-03-02 14:25:30 +0100147
148
149my $t0 = Benchmark->new;
150my $cmp = timethese($iter => $models);
151
152print "\n----------------------------------\n";
153
154foreach my $tool (sort keys %$cmp) {
155 my $seconds_per_run = $cmp->{$tool}->[0] / $cmp->{$tool}->[5];
156 my $tokens_per_msecond = ($effi_wc / $seconds_per_run) / 1000;
157 print $tool, "\t", $seconds_per_run, "\t", $tokens_per_msecond, "\t", sprintf("%.2f", $tokens_per_msecond), "\n";
158};
159
160print "\n----------------------------------\n";
161
162cmpthese($cmp);
163
164print "Benchmarking took: ", timestr(timediff(Benchmark->new, $t0)), "\n";
165