# tbench1.pl - Simple benchmark of Organism class. # Generate blinker test file with, for example: # perl createblinker.pl 500000 -900000 100 >x.tmp 2>y.tmp # then run this script for two ticks, for example: # perl tbench1.pl x.tmp 2 use strict; use warnings; use Organism; # XXX: To read Life 1.06 file, ignore leading line containing "#Life 1.06" sub read_cells { my $fname = shift; open( my $fh, '<', $fname ) or die "error: open '$fname': $!"; map { [ split ' ' ] } <$fh>; } @ARGV == 2 or die "usage: $0 file nticks\n"; my $file = shift; my $nticks = shift; $nticks =~ /^\d+$/ or die "error: nticks ($nticks) not a number"; my $org = Organism->new(); { my @cells = read_cells($file); $org->insert_cells(@cells); my $ncells = $org->count(); print "cell count at start = $ncells\n"; $ncells == scalar(@cells) or die "oops"; # Uncomment for tile dump # $org->dump_tiles(); } warn "run benchmark for $nticks ticks\n"; my $tstart = time; # for my $i ( 1 .. $nticks ) { $org->tick() } $org->ticks($nticks); my $tend = time; my $taken = $tend - $tstart; my $ncells = $org->count(); # Uncomment for diff with goodlidkaout.txt # { # my @vcells = $org->get_live_cells(); # my $cnt = 0; # for my $c (@vcells) { # ++$cnt; # print "$cnt: $c->[0],$c->[1]\n"; # } # $cnt == $ncells or warn "error: $cnt != $ncells\n"; # } print "cell count at end = $ncells\n"; warn "time taken: $taken secs\n"; # Uncomment for tile dump # $org->dump_tiles();