Added benchmark mechanism

Change-Id: Ia49ce229b3812faca178babb0c8ab54afcb349eb
diff --git a/.gitignore b/.gitignore
index 91a0d5a..f2eb48a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
 Sandbox
 examples
 benchmark
+benchmark.csv
 docs
 todo.org
 tools
diff --git a/Changes b/Changes
index 5f5b710..267bf0c 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,4 @@
-0.39 2020-02-11
+0.39 2020-02-19
         - Added Talismane support.
         - Added "distributor" field to I5 metadata.
         - Added DGD link field to I5 metadata.
@@ -9,6 +9,7 @@
         - Fixed parsing of editionStmt.
         - Added documentation for supported I5 metadata
           fields.
+        - Added integrated benchmark mechanism.
 
 0.38 2019-05-22
         - Stop file processing when base tokenization
diff --git a/Makefile.PL b/Makefile.PL
index 370a0ae..6d61c3f 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -27,6 +27,7 @@
     'IO::Dir::Recursive' => 0.03,
     'File::Temp'      => 0,
     'Directory::Iterator' => 0,
+    'Dumbbench'       => '0.111',
     'Benchmark'       => 0,
     'Unicode::Normalize' => 0,
     'Carp'            => 0,
diff --git a/xt/benchmark.pl b/xt/benchmark.pl
new file mode 100644
index 0000000..f7d0cb0
--- /dev/null
+++ b/xt/benchmark.pl
@@ -0,0 +1,87 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Dumbbench;
+use File::Basename 'dirname';
+use File::Spec::Functions qw/catfile catdir rel2abs/;
+use File::Temp ':POSIX';
+use FindBin;
+use Getopt::Long;
+
+BEGIN {
+  unshift @INC, "$FindBin::Bin/../lib";
+};
+
+my $columns = 0;
+my $no_header = 0;
+GetOptions(
+  'columns|c' => \$columns,
+  'no-header|n' => \$no_header,
+  'help|h' => sub {
+    print "--columns|-c     Print instances in columns\n";
+    print "--no-header|-n   Dismiss benchmark names\n";
+    print "--help|-h        Print this page\n\n";
+    exit(0);
+  }
+);
+
+our $SCRIPT_NAME = 'korapxml2krill';
+
+my $f = dirname(__FILE__);
+my $script = rel2abs(catfile($f, '..', 'script', $SCRIPT_NAME));
+
+
+# begin instance 1 setup
+# Load example file
+my $input = rel2abs(catdir($f, '..', 't', 'annotation', 'corpus', 'doc', '0001'));
+my $output = tmpnam();
+my $cache = tmpnam();
+# end instance 1
+
+# Create a new benchmark object
+my $bench = Dumbbench->new(
+  verbosity => 0
+);
+
+# Add benchmark instances
+$bench->add_instances(
+  Dumbbench::Instance::PerlSub->new(
+    name => 'ExampleRun 1',
+    code => sub {
+      my $cmd = join(
+        ' ',
+        'perl', $script,
+        '--input' => $input,
+        '--output' => $output,
+        '--cache' => $cache,
+        '-k' => '0.03',
+        '-t' => 'OpenNLP#Tokens',
+        '-l' => 'ERROR',
+        '>' => '/dev/null'
+      );
+      `$cmd`;
+    }
+  )
+);
+
+# Run benchmarks
+$bench->run;
+
+# Output in a single row
+if ($columns) {
+  unless ($no_header) {
+    print join("\t", map { $_->name } $bench->instances), "\n";
+  };
+  print join("\t", map { $_->single_run } $bench->instances), "\n";
+  exit(0);
+};
+
+# Output simple timings for comparation
+foreach my $inst ($bench->instances) {
+  unless ($no_header) {
+    print $inst->name, ': ';
+  };
+  print $inst->single_run, "\n";
+};
+
+exit(0);