[a8 b4 c1 d3 e6 f2 g7 h5]
[a9 b7 c4 d2 e8 f6 g1 h3 i5]
####
N Original Faster Non-Pure
4 0.06 0.05 0.04
5 0.07 0.04 0.05
6 1.57 0.07 0.05
7 9.29 0.06 0.05
8 0.23 0.06
9 0.16 0.06
10 0.50 0.07
11 0.41 0.07
12 2.64 0.14
13 1.58 0.10
14 37.23 0.82
15 35.45 0.70
16 5.45
17 3.18
18 27.17
19 1.89
20
##
##
#!/usr/bin/perl
use strict;
use warnings;
no warnings qw /syntax/;
$| = 1;
my $width = 15;
my $time_out = 120;
my @cmds = ("./queens2 -n ",
"./queens3 -n ",
"./queens1 -f -n ");
my $nr_of_commands = @cmds;
my $N = 4;
print " N";
printf "%${width}s" => $_ for qw /Original Faster Non-Pure/;
print "\n";
while ($nr_of_commands) {
printf "%3d" => $N;
foreach my $cmd (@cmds) {
unless (defined $cmd) {
print " " x $width;
next;
}
local $SIG {ALRM} = sub {die "Time out!"};
alarm ($time_out);
eval {
my $time = (`/usr/bin/time -f "%U" $cmd $N 2>&1`) [-1];
alarm (0);
chomp $time;
printf "%$width.2f" => $time;
};
if ($@ && $@ =~ /Time out/) {
undef $cmd;
$nr_of_commands --;
print " " x $width;
}
}
print "\n";
$N ++;
}