← Index
NYTProf Performance Profile   « block view • line view • sub view »
For ./testnewboardincnply
  Run on Mon Jan 12 21:52:27 2015
Reported on Mon Jan 12 22:01:18 2015

Filename/homes/dcw/src/perl/coloroids_solver/NewBoard.pm
StatementsExecuted 137237976 statements in 52.4s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
141452304121.3s21.3sNewBoard::::cellstatusNewBoard::cellstatus
55843212.7s27.5sNewBoard::::changeregioncolourNewBoard::changeregioncolour
55854312.3s25.1sNewBoard::::extendregionNewBoard::extendregion
2811488114.51s4.51sNewBoard::::markcellcolourNewBoard::markcellcolour
674063721.09s1.09sNewBoard::::cellNewBoard::cell
24787561397ms397msNewBoard::::markcellstatusNewBoard::markcellstatus
5721166ms166msNewBoard::::as_stringNewBoard::as_string
5579228.74ms8.74msNewBoard::::solvedNewBoard::solved
6757528.26ms8.26msNewBoard::::regionNewBoard::region
1112.34ms2.47msNewBoard::::BEGIN@25NewBoard::BEGIN@25
1112.10ms2.29msNewBoard::::BEGIN@24NewBoard::BEGIN@24
1111.91ms2.06msNewBoard::::BEGIN@26NewBoard::BEGIN@26
1111.49ms1.49msNewBoard::::CORE:openNewBoard::CORE:open (opcode)
1111.01ms1.01msNewBoard::::BEGIN@17NewBoard::BEGIN@17
111547µs5.29msNewBoard::::mkboardNewBoard::mkboard
111539µs7.36msNewBoard::::newfromfileNewBoard::newfromfile
111407µs2.44msNewBoard::::BEGIN@23NewBoard::BEGIN@23
111231µs231µsNewBoard::::BEGIN@43NewBoard::BEGIN@43
111225µs3.30msNewBoard::::BEGIN@21NewBoard::BEGIN@21
373127µs27µsNewBoard::::CORE:readlineNewBoard::CORE:readline (opcode)
11111µs35µsNewBoard::::BEGIN@28NewBoard::BEGIN@28
1119µs81µsNewBoard::::BEGIN@30NewBoard::BEGIN@30
1116µs6µsNewBoard::::CORE:closeNewBoard::CORE:close (opcode)
1116µs99µsNewBoard::::BEGIN@18NewBoard::BEGIN@18
1115µs33µsNewBoard::::BEGIN@17.3NewBoard::BEGIN@17.3
1115µs23µsNewBoard::::BEGIN@19NewBoard::BEGIN@19
1111µs1µsNewBoard::::boardsizeNewBoard::boardsize
0000s0sNewBoard::::as_plain_stringNewBoard::as_plain_string
0000s0sNewBoard::::newNewBoard::new
0000s0sNewBoard::::newrandomNewBoard::newrandom
0000s0sNewBoard::::sizeNewBoard::size
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package NewBoard;
2
3#
4# new version of board object... represents much more information about
5# the state of the game so we can lookup more answers and spend less
6# time calculating.
7# a NewBoard stores the following:
8# GRID: ref to array of row
9# [row = ref to even-length pair array (colour,status)]
10# R: no of rows
11# C: no of columns
12# SIZE: R * C: no of cells in board
13# REGSIZE: Region size (no of cells in region)
14# ADJCOLBAG: bag of colours of cells immediately
15# adjacent to region.
16
17464µs31.07ms
# spent 1.01ms within NewBoard::BEGIN@17 which was called: # once (1.01ms+0s) by main::BEGIN@12 at line 17 # spent 33µs (5+27) within NewBoard::BEGIN@17.3 which was called: # once (5µs+27µs) by main::BEGIN@12 at line 17
use v5.12;
# spent 1.01ms making 1 call to NewBoard::BEGIN@17 # spent 33µs making 1 call to NewBoard::BEGIN@17.3 # spent 27µs making 1 call to feature::import
18221µs2192µs
# spent 99µs (6+93) within NewBoard::BEGIN@18 which was called: # once (6µs+93µs) by main::BEGIN@12 at line 18
use Function::Parameters;
# spent 99µs making 1 call to NewBoard::BEGIN@18 # spent 93µs making 1 call to Function::Parameters::import
19219µs240µs
# spent 23µs (5+18) within NewBoard::BEGIN@19 which was called: # once (5µs+18µs) by main::BEGIN@12 at line 19
use Data::Dumper;
# spent 23µs making 1 call to NewBoard::BEGIN@19 # spent 18µs making 1 call to Exporter::import
20
21285µs26.32ms
# spent 3.30ms (225µs+3.07) within NewBoard::BEGIN@21 which was called: # once (225µs+3.07ms) by main::BEGIN@12 at line 21
use parent 'Clone'; # automatic cloning
# spent 3.30ms making 1 call to NewBoard::BEGIN@21 # spent 3.03ms making 1 call to parent::import
22
23286µs24.45ms
# spent 2.44ms (407µs+2.04) within NewBoard::BEGIN@23 which was called: # once (407µs+2.04ms) by main::BEGIN@12 at line 23
use lib qw(/homes/dcw/lib/perl5/DCW);
# spent 2.44ms making 1 call to NewBoard::BEGIN@23 # spent 2.01ms making 1 call to lib::import
2421.73ms22.33ms
# spent 2.29ms (2.10+198µs) within NewBoard::BEGIN@24 which was called: # once (2.10ms+198µs) by main::BEGIN@12 at line 24
use Tuple qw(tuple);
# spent 2.29ms making 1 call to NewBoard::BEGIN@24 # spent 34µs making 1 call to Exporter::import
2521.65ms22.51ms
# spent 2.47ms (2.34+127µs) within NewBoard::BEGIN@25 which was called: # once (2.34ms+127µs) by main::BEGIN@12 at line 25
use List qw(list);
# spent 2.47ms making 1 call to NewBoard::BEGIN@25 # spent 37µs making 1 call to Exporter::import
2621.62ms12.06ms
# spent 2.06ms (1.91+152µs) within NewBoard::BEGIN@26 which was called: # once (1.91ms+152µs) by main::BEGIN@12 at line 26
use Sorthash;
# spent 2.06ms making 1 call to NewBoard::BEGIN@26
27
28241µs259µs
# spent 35µs (11+24) within NewBoard::BEGIN@28 which was called: # once (11µs+24µs) by main::BEGIN@12 at line 28
use overload '""' => \&as_string;
# spent 35µs making 1 call to NewBoard::BEGIN@28 # spent 24µs making 1 call to overload::import
29
30
# spent 81µs (9+72) within NewBoard::BEGIN@30 which was called: # once (9µs+72µs) by main::BEGIN@12 at line 35
use constant {
3117µs172µs COLOUR => 0,
# spent 72µs making 1 call to constant::import
32 STATUS => 1,
33 INREGION => 1,
34 ADJACENT => 2,
35152µs181µs};
# spent 81µs making 1 call to NewBoard::BEGIN@30
36
37
38#
39# my $board = Board->new( @boardarray );
40# Build a new board object and return it.
41# @boardarray is an array of array refs of cells (colours)
42#
4321.82ms36.60ms
# spent 231µs within NewBoard::BEGIN@43 which was called: # once (231µs+0s) by main::BEGIN@12 at line 43
method new( $class: @boardarray )
# spent 3.29ms making 1 call to utf8::AUTOLOAD # spent 3.08ms making 1 call to utf8::SWASHNEW # spent 231µs making 1 call to NewBoard::BEGIN@43
44{
45 return mkboard( $class, @boardarray );
46}
47
48
49#
50# my $board = Board->newfromfile( $filename );
51# Build a new board object by opening and reading a file.
52#
53
# spent 7.36ms (539µs+6.82) within NewBoard::newfromfile which was called: # once (539µs+6.82ms) by main::RUNTIME at line 34 of testnewboardincnply
method newfromfile( $class: $filename )
542600ns{
5511.50ms11.49ms open( my $in, '<', $filename ) || die;
# spent 1.49ms making 1 call to NewBoard::CORE:open
56114µs19µs $_ = <$in>;
# spent 9µs making 1 call to NewBoard::CORE:readline
5714µs my( $w, $h ) = split( /\s+/, $_, 2 );
581200ns my @array;
5914µs1700ns while( <$in> )
# spent 700ns making 1 call to NewBoard::CORE:readline
60 {
61356µs chomp;
6235478µs3516µs push @array, [ split( /\s+/, $_ ) ];
# spent 16µs making 35 calls to NewBoard::CORE:readline, avg 471ns/call
63 }
64110µs16µs close( $in );
# spent 6µs making 1 call to NewBoard::CORE:close
65146µs15.29ms return mkboard( $class, @array );
# spent 5.29ms making 1 call to NewBoard::mkboard
661100ns}
67
68
69#
70# my $board = Board->newrandom( $w, $h, @colours );
71# Build a new board object of width $w and height $h
72# with random colours from @colours.
73#
74method newrandom( $class: $w, $h, @colours )
75{
76 my @array;
77 foreach my $i (1..$h)
78 {
79 my @row = map { $colours[int rand(@colours)] } 1..$w;
80 push @array, \@row;
81 }
82 return mkboard( $class, @array );
83}
84
85
86#
87# my $board = mkboard( $class, @array );
88# Real constructor: turn @array (2-d array of colours)
89# into a NewBoard object
90#
91
# spent 5.29ms (547µs+4.75) within NewBoard::mkboard which was called: # once (547µs+4.75ms) by NewBoard::newfromfile at line 65
method mkboard( $class: @array )
9223µs{
931500ns my $rows = @array;
941400ns my $cols = @{$array[0]};
951459µs my @grid = map { [ map { $_, 0 } @$_ ] } @array;
96 #die Dumper \@grid;
97 # make initial state: region is 0,0, adjacents are 0,1 and 1,0
981200ns my $regionsize = 1;
9914µs126µs my $adjcolbag = Sorthash->new;
# spent 26µs making 1 call to Sorthash::new
100157µs my $board = bless {
101 R => $rows,
102 C => $cols,
103 GRID => \@grid,
104 SIZE => $rows * $cols,
105 REGSIZE => $regionsize,
106 ADJCOLBAG => $adjcolbag,
107 }, $class;
10812µs15µs $board->markcellstatus( 0, 0, INREGION ); # mark 0,0 as inregion
# spent 5µs making 1 call to NewBoard::markcellstatus
10911µs12µs $board->markcellstatus( 0, 1, ADJACENT ); # mark 0,1 as adjacent
# spent 2µs making 1 call to NewBoard::markcellstatus
1101900ns12µs $board->markcellstatus( 1, 0, ADJACENT ); # mark 1,0 as adjacent
# spent 2µs making 1 call to NewBoard::markcellstatus
11112µs13µs $adjcolbag->{ $board->cell( 0, 1 ) }++;
# spent 3µs making 1 call to NewBoard::cell
11212µs12µs $adjcolbag->{ $board->cell( 1, 0 ) }++;
# spent 2µs making 1 call to NewBoard::cell
113 #die Dumper $board;
11411µs14.70ms $board->extendregion;
# spent 4.70ms making 1 call to NewBoard::extendregion
115 #die Dumper $board;
116 #die $board;
11713µs return $board;
11810s}
119
120
121#
122# my $newboard = $board->clone;
123# Clone a new board object and return it.
124# Provided by 'Clone' parent class.
125#
126#DCWmethod clone
127#DCW{
128#DCW my $adjcolbag = Sorthash->new;
129#DCW %$adjcolbag = %{$self->{ADJCOLBAG}};
130#DCW my @grid = map {
131#DCW [ map { Tuple->new(@$_) } @$_ ]
132#DCW } @{$self->{GRID}};
133#DCW my $newboard = bless {
134#DCW R => $self->{R},
135#DCW C => $self->{C},
136#DCW GRID => \@grid,
137#DCW SIZE => $self->{SIZE},
138#DCW REGSIZE => $self->{REGSIZE},
139#DCW ADJCOLBAG => $adjcolbag,
140#DCW }, ref($self);
141#DCW}
142
- -
145#
146# my $colour = $board->cell( $r, $c );
147# Extract a specific cell colour ($r,$c) from the board
148#
149
# spent 1.09s within NewBoard::cell which was called 674063 times, avg 2µs/call: # 382848 times (617ms+0s) by NewBoard::extendregion at line 285, avg 2µs/call # 180541 times (295ms+0s) by NewBoard::extendregion at line 329, avg 2µs/call # 103908 times (168ms+0s) by NewBoard::extendregion at line 303, avg 2µs/call # 5585 times (10.8ms+0s) by NewBoard::extendregion at line 272, avg 2µs/call # 1179 times (3.06ms+0s) by main::fulllist_all_nply at line 65 of NewIncNPlyPicker.pm, avg 3µs/call # once (3µs+0s) by NewBoard::mkboard at line 111 # once (2µs+0s) by NewBoard::mkboard at line 112
method cell( $r, $c )
1501348126231ms{
15167406398.5ms my $pos = $c<<1;
152674063177ms my $row = $self->{GRID}[$r];
15367406398.1ms my $colour = $row->[$pos];
154674063804ms return $colour;
155}
156
157
158#
159# my $status = $board->cellstatus( $r, $c );
160# Extract the status (0, INREGION or ADJACENT) of cell ($r,$c)
161#
162
# spent 21.3s within NewBoard::cellstatus which was called 14145230 times, avg 2µs/call: # 6841625 times (10.3s+0s) by NewBoard::extendregion at line 282, avg 2µs/call # 6840400 times (10.3s+0s) by NewBoard::changeregioncolour at line 364, avg 2µs/call # 359297 times (562ms+0s) by NewBoard::extendregion at line 326, avg 2µs/call # 103908 times (161ms+0s) by NewBoard::extendregion at line 304, avg 2µs/call
method cellstatus( $r, $c )
163282904604.71s{
164141452303.99s my $row = $self->{GRID}[$r];
165141452302.45s my $pos = $c<<1|1;
166141452301.34s my $status = $row->[$pos];
1671414523015.2s return $status;
16810s}
169
170
171#
172# $board->markcellcolour( $r, $c, $col );
173# Mark ($r,$c)' cell as INREGION and colour $col
174#
175
# spent 4.51s within NewBoard::markcellcolour which was called 2811488 times, avg 2µs/call: # 2811488 times (4.51s+0s) by NewBoard::changeregioncolour at line 365, avg 2µs/call
method markcellcolour( $r, $c, $col )
17656229761.19s{
1772811488861ms my $row = $self->{GRID}[$r];
1782811488381ms my $pos = $c<<1;
17928114883.29s $row->[$pos] = $col;
180 #print "debug: mcc($r,$c,$col): row $r [$pos] = $col\n";
181}
182
183
184#
185# $board->markcellstatus( $r, $c, $status );
186# Mark ($r,$c)' cellstatus as status
187#
188
# spent 397ms within NewBoard::markcellstatus which was called 247875 times, avg 2µs/call: # 92115 times (146ms+0s) by NewBoard::extendregion at line 313, avg 2µs/call # 78893 times (134ms+0s) by NewBoard::extendregion at line 289, avg 2µs/call # 76864 times (117ms+0s) by NewBoard::extendregion at line 342, avg 2µs/call # once (5µs+0s) by NewBoard::mkboard at line 108 # once (2µs+0s) by NewBoard::mkboard at line 109 # once (2µs+0s) by NewBoard::mkboard at line 110
method markcellstatus( $r, $c, $status )
189495750102ms{
19024787577.2ms my $row = $self->{GRID}[$r];
19124787548.2ms my $pos = $c<<1|1;
192247875288ms $row->[$pos] = $status;
193 #die "debug: markcellstatus($r, $c, $status): row[$pos] = $status\n";
19410s}
195
196
197#
198# my( $rows, $cols) = $board->size();
199# Extract the size (rows x cols) of $board.
200#
201method size
202{
203 return ( $self->{R}, $self->{C} );
204}
205
206
207#
208# my $isover = $board->solved;
209# Is the game over?
210#
211method solved
21255791.16ms
# spent 8.74ms within NewBoard::solved which was called 5579 times, avg 2µs/call: # 5522 times (8.18ms+0s) by main::fulllist_all_nply at line 101 of NewIncNPlyPicker.pm, avg 1µs/call # 57 times (557µs+0s) by main::solve_game at line 29 of NewSolveGame.pm, avg 10µs/call
{
213557910.3ms return $self->{SIZE} == $self->{REGSIZE};
21410s}
215
216
217#
218# my $size = $board->boardsize;
219# how many cells are in the board?
220method boardsize
2211200ns
# spent 1µs within NewBoard::boardsize which was called: # once (1µs+0s) by main::incnply_pick_best at line 192 of NewIncNPlyPicker.pm
{
22213µs return $self->{SIZE};
223}
224
225
226#
227# my( $ninregion, $adjcolbag ) = $board->region;
228# return information about the region:
229# the regionsize and the adjacent colour bag
230#
231method region
23267571.15ms
# spent 8.26ms within NewBoard::region which was called 6757 times, avg 1µs/call: # 5515 times (6.60ms+0s) by main::fulllist_all_nply at line 104 of NewIncNPlyPicker.pm, avg 1µs/call # 1179 times (1.50ms+0s) by main::fulllist_all_nply at line 68 of NewIncNPlyPicker.pm, avg 1µs/call # 56 times (153µs+0s) by main::solve_game at line 31 of NewSolveGame.pm, avg 3µs/call # 6 times (8µs+0s) by main::fulllist_all_nply at line 79 of NewIncNPlyPicker.pm, avg 1µs/call # once (1µs+0s) by main::solve_game at line 42 of NewSolveGame.pm
{
233675710.3ms return ( $self->{REGSIZE}, $self->{ADJCOLBAG} );
23410s}
235
236
237#
238# foreach_cell( $self, $property, $callback );
239# For each cell in board that has $property (INREGION|ADJACENT)
240# invoke the coderef $callback with the row and the column and
241# the tuple.
242#
243#DCWmethod foreach_cell( $property, $callback )
244#DCW{
245#DCW my $rows = $self->{R};
246#DCW my $cols = $self->{C};
247#DCW my $g = $self->{GRID};
248#DCW foreach my $r (0..$rows-1)
249#DCW {
250#DCW my $row = $self->{GRID}[$r];
251#DCW foreach my $c (0..$cols-1)
252#DCW {
253#DCW my $colour = lc( substr($row, 2*$c, 1) );
254#DCW my $tuple = $gr->[$c];
255#DCW $callback->( $r, $c, $tuple ) if
256#DCW $tuple->[STATUS] == $property;
257#DCW }
258#DCW }
259#DCW}
260
26114µs443µsmy @delta = ( tuple(0,1), tuple(1,0), tuple(0,-1), tuple(-1,0) );
# spent 43µs making 4 calls to Tuple::tuple, avg 11µs/call
262
263#
264# $board->extendregion;
265# After changing the board, locate all cells that should join the
266# region, ie. which are now of the same colour as the region.
267# Start by locating the existing adjacent cells of the region colour,
268# then flood fill out from there. also updates the adjacent information.
269#
270method extendregion
2715585802µs
# spent 25.1s (12.3+12.8) within NewBoard::extendregion which was called 5585 times, avg 4.50ms/call: # 5522 times (12.1s+12.7s) by main::fulllist_all_nply at line 98 of NewIncNPlyPicker.pm, avg 4.50ms/call # 56 times (129ms+134ms) by main::solve_game at line 38 of NewSolveGame.pm, avg 4.71ms/call # 6 times (10.3ms+11.1ms) by main::fulllist_all_nply at line 78 of NewIncNPlyPicker.pm, avg 3.57ms/call # once (2.28ms+2.42ms) by NewBoard::mkboard at line 114
{
27255854.91ms558510.8ms my $regioncolour = $self->cell(0,0);
# spent 10.8ms making 5585 calls to NewBoard::cell, avg 2µs/call
27355852.07ms my $adjcolbag = $self->{ADJCOLBAG};
27455851.08ms my $rows = $self->{R};
2755585929µs my $cols = $self->{C};
2765585698µs my @todo;
277 # foreach adjacent cell of the regioncolour
27855853.47ms foreach my $r (0..$rows-1)
279 {
280195475153ms foreach my $c (0..$cols-1)
281 {
28268416254.58s684162510.3s my $status = $self->cellstatus( $r, $c );
# spent 10.3s making 6841625 calls to NewBoard::cellstatus, avg 2µs/call
28368416251.87s if( $status == ADJACENT )
284 {
285382848279ms382848617ms my $colour = $self->cell( $r, $c );
# spent 617ms making 382848 calls to NewBoard::cell, avg 2µs/call
286382848103ms next unless $colour eq $regioncolour;
2877889364.6ms78893286ms push @todo, tuple($r,$c);
# spent 286ms making 78893 calls to Tuple::tuple, avg 4µs/call
288 # no longer adjacent
2897889367.1ms78893134ms $self->markcellstatus( $r, $c, 0 );
# spent 134ms making 78893 calls to NewBoard::markcellstatus, avg 2µs/call
290 }
291 }
292 }
293 #print "debug: extendregion, extracted adjacent cells and neutered them\n";
294 #print "board is now:\n$self\ntodo is ", join(',', @todo), "\n";
295 # now @todo is all adjacent cells of regioncolour
29655853.66ms delete $adjcolbag->{$regioncolour}; # nothing adjacent
297 # adapted find linked colour code (aka flood fill) from here
298558512.0ms while( @todo )
299 {
30010390817.9ms my $pair = shift @todo;
301 #DCWmy( $r, $c ) = $pair->detuple;
30210390835.3ms my( $r, $c ) = @$pair;
30310390883.4ms103908168ms my $cellcolour = $self->cell( $r, $c );
# spent 168ms making 103908 calls to NewBoard::cell, avg 2µs/call
30410390874.8ms103908161ms my $status = $self->cellstatus( $r, $c );
# spent 161ms making 103908 calls to NewBoard::cellstatus, avg 2µs/call
305 #print "debug: floodfill: cell $r,$c, colour $cellcolour, status $status\n";
30610390814.9ms die "extendregion: cell($r,$c), colour $cellcolour, ".
307 "should be $regioncolour\n" unless
308 $cellcolour eq $regioncolour;
309 # mark this cell as in the region - skipping cells already
310 # in the region (eg. one cell reachable in the same move
311 # via two different paths)
31210390815.3ms next if $status == INREGION;
3139211564.2ms92115146ms $self->markcellstatus( $r, $c, INREGION );
# spent 146ms making 92115 calls to NewBoard::markcellstatus, avg 2µs/call
3149211518.0ms $self->{REGSIZE}++;
315 # look at NSEW neighbours
31692115131ms foreach my $dp (@delta)
317 {
318 #DCWmy( $dr, $dc ) = $dp->detuple;
319368460101ms my( $dr, $dc ) = @$dp;
32036846067.2ms my $tr = $r + $dr;
32136846031.3ms my $tc = $c + $dc;
322 # are we off the edge?
32336846084.5ms next if $tr < 0 || $tr >= $rows
324 || $tc < 0 || $tc >= $cols;
325 # have we already seen this cell?
326359297265ms359297562ms my $status = $self->cellstatus( $tr, $tc );
# spent 562ms making 359297 calls to NewBoard::cellstatus, avg 2µs/call
32735929766.0ms next if $status == INREGION;
328 # ok, new cell.. process
329180541145ms180541295ms my $neighbourcolour = $self->cell($tr,$tc);
# spent 295ms making 180541 calls to NewBoard::cell, avg 2µs/call
330 #print "debug: process neighbour cell ($tr,$tc), colour=$neighbourcolour\n";
33118054162.4ms if( $neighbourcolour eq $regioncolour )
332 {
3332501520.4ms2501589.1ms push @todo, tuple($tr,$tc);
# spent 89.1ms making 25015 calls to Tuple::tuple, avg 4µs/call
334250159.33ms next unless $status == ADJACENT;
335 # no longer ADJACENT
336 $self->markcellstatus( $tr, $tc, 0 );
337 # nb: cells on todo list will end up INREGION
338 $adjcolbag->{$regioncolour}--;
339 } else
340 {
34115552633.9ms next if $status == ADJACENT;
3427686449.9ms76864117ms $self->markcellstatus( $tr, $tc, ADJACENT );
# spent 117ms making 76864 calls to NewBoard::markcellstatus, avg 2µs/call
3437686426.5ms $adjcolbag->{$neighbourcolour}++;
344 }
345 }
346 }
347}
348
349
350#
351# $board->changeregioncolour( $newcolour );
352# Change the colour of the whole region to $newcolour
353# NB: we do not extend the region at the end of this,
354# the caller should do that again.
355#
356
# spent 27.5s (12.7+14.8) within NewBoard::changeregioncolour which was called 5584 times, avg 4.93ms/call: # 5522 times (12.6s+14.6s) by main::fulllist_all_nply at line 97 of NewIncNPlyPicker.pm, avg 4.93ms/call # 56 times (126ms+147ms) by main::solve_game at line 37 of NewSolveGame.pm, avg 4.88ms/call # 6 times (18.0ms+22.8ms) by main::fulllist_all_nply at line 77 of NewIncNPlyPicker.pm, avg 6.80ms/call
method changeregioncolour( $newcolour )
357111684.11ms{
35855843.33ms my $rows = $self->{R};
35955841.12ms my $cols = $self->{C};
360558412.1ms foreach my $r (0..$rows-1)
361 {
362195440125ms foreach my $c (0..$cols-1)
363 {
36468404004.53s684040010.3s my $status = $self->cellstatus( $r, $c );
# spent 10.3s making 6840400 calls to NewBoard::cellstatus, avg 2µs/call
36568404003.67s28114884.51s $self->markcellcolour( $r, $c, $newcolour )
# spent 4.51s making 2811488 calls to NewBoard::markcellcolour, avg 2µs/call
366 if $status == INREGION;
367 }
368 }
369 #print "debug crc board now $self\n";
3701100ns}
371
372
373#
374# my $str = $board->as_string;
375# Generate a printable string form of a complete board
376# Return the printable firm of a board
377#
378method as_string
3795726µs
# spent 166ms within NewBoard::as_string which was called 57 times, avg 2.91ms/call: # 56 times (165ms+0s) by main::solve_game at line 32 of NewSolveGame.pm, avg 2.94ms/call # once (906µs+0s) by main::solve_game at line 43 of NewSolveGame.pm
{
3805750µs my $rows = $self->{R};
3815740µs my $cols = $self->{C};
3825722µs my $str = "\t";
38357197µs foreach my $col (0..$cols-1)
384 {
3851995648µs $str .= sprintf( "%2d", $col );
386 }
3875723µs $str .= "\n";
3885745µs foreach my $row (0..$rows-1)
389 {
3901995691µs $str .= sprintf( " %2d ", $row );
3911995670µs my $rowarr = $self->{GRID}[$row];
3921995167µs my $pos = 0;
3931995931µs foreach my $col (0..$cols-1)
394 {
395698259.11ms my $colour = $rowarr->[$pos++];
396698258.81ms my $status = $rowarr->[$pos++];
397698255.52ms my $extra = " ";
398698256.33ms $colour = uc($colour) if $status == INREGION;
399698253.80ms $extra = '+' if $status == ADJACENT;
4006982514.7ms $str .= "$colour$extra";
401 }
4021995464µs $str .= "\n";
403 }
40457114ms return $str;
405}
406
407
408#
409# my $str = $board->as_plain_string;
410# Build and return a printable plain string form of a board,
411# with no status information
412#
413method as_plain_string
414{
415 my $rows = $self->{R};
416 my $cols = $self->{C};
417 my $str = "$rows $cols\n";
418 foreach my $row (0..$rows-1)
419 {
420 foreach my $col (0..$cols-1)
421 {
422 $str .= $self->cell($row,$col). " ";
423 }
424 $str .= "\n";
425 }
426 return $str;
4271100ns}
428
429
43015µs1;
 
# spent 6µs within NewBoard::CORE:close which was called: # once (6µs+0s) by NewBoard::newfromfile at line 64
sub NewBoard::CORE:close; # opcode
# spent 1.49ms within NewBoard::CORE:open which was called: # once (1.49ms+0s) by NewBoard::newfromfile at line 55
sub NewBoard::CORE:open; # opcode
# spent 27µs within NewBoard::CORE:readline which was called 37 times, avg 719ns/call: # 35 times (16µs+0s) by NewBoard::newfromfile at line 62, avg 471ns/call # once (9µs+0s) by NewBoard::newfromfile at line 56 # once (700ns+0s) by NewBoard::newfromfile at line 59
sub NewBoard::CORE:readline; # opcode