bench.pl added
authorNeszt Tibor <neszt.tibor@euronetrt.hu>
Tue, 14 Apr 2015 12:39:38 +0000 (14:39 +0200)
committerNeszt Tibor <neszt.tibor@euronetrt.hu>
Tue, 14 Apr 2015 12:39:38 +0000 (14:39 +0200)
bench.pl [new file with mode: 0755]

diff --git a/bench.pl b/bench.pl
new file mode 100755 (executable)
index 0000000..fd938ee
--- /dev/null
+++ b/bench.pl
@@ -0,0 +1,76 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use JSON::XS;
+use Time::HiRes qw(gettimeofday tv_interval);
+use Text::ASCIITable;
+
+sub run {#{{{
+       my $cmd = shift;
+
+       my $start = [gettimeofday];
+       system($cmd);
+
+       return sprintf('%.3fs', tv_interval($start));
+}#}}}
+
+sub main {#{{{
+
+       system('mkdir -p outputs');
+
+       my $all = {
+               cpp => {
+                       pre => 'clang++ -O2 -o uwc.exe uwc.cpp -std=c++11 -stdlib=libc++',
+                       cmd => './uwc.exe',
+               },
+               sh => {
+                       pre => '',
+                       cmd => 'sh ./uwc.sh',
+               },
+               php => {
+                       pre => '',
+                       cmd => 'php ./uwc.php',
+               },
+               pl => {
+                       pre => '',
+                       cmd => 'perl ./uwc.pl',
+               },
+               py => {
+                       pre => '',
+                       cmd => 'python uwc.py',
+               },
+               rb => {
+                       pre => '',
+                       cmd => 'ruby uwc.rb',
+               },
+       };
+
+       my $r = {};
+
+       my $fieldnames = ['Lang'];
+       opendir (DIR, 'inputs') or die $!;
+       while (my $file = readdir(DIR)) {
+               $file =~ /^\./ and next;
+
+               push @{$fieldnames}, $file;
+               foreach my $p ( keys %{$all} ) {
+                       my $e = $all->{$p};
+
+                       print "Processing $file with $p\n";
+                       system($e->{pre}) if $e->{pre};
+                       $r->{$p}->{$file} = run("$e->{cmd} < inputs/$file > outputs/${p}_${file}");
+               }
+       }
+       closedir(DIR);
+
+       my $t = Text::ASCIITable->new({ headingText => 'Summary', utf8 => 0 });
+       $t->setCols(@{$fieldnames});
+       foreach my $p ( sort keys %{$r} ) {
+               $t->addRow(map { $_ eq 'Lang' ? $p : $r->{$p}->{$_} } @{$fieldnames});
+       }
+
+       print $t->draw;
+}#}}}
+
+exit main(@ARGV);