Skip to content

Commit 032b9d1

Browse files
committed
more timing
1 parent 493081f commit 032b9d1

3 files changed

Lines changed: 45 additions & 15 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

solitaire-solver/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ edition = "2024"
1010
rustc-hash = "2.1.1"
1111
nohash-hasher = "0.2.0"
1212
rayon = "1.11.0"
13+
log = "0.4.29"
1314

1415
[target.'cfg(target_arch = "wasm32")'.dependencies]
1516
voracious_radix_sort = { git = "https://github.com/lakwet/voracious_sort" }

solitaire-solver/src/lib.rs

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ mod mov;
88
mod solution;
99
mod sort;
1010

11+
use log::info;
12+
1113
pub use calc_first::calculate_first_solution;
1214
pub use calc_naive::calculate_all_solutions_naive;
1315
pub use calc_success::calculate_p_random_chance_success;
@@ -262,31 +264,43 @@ pub fn calculate_all_solutions(threads: Option<NonZero<usize>>) -> Vec<Board> {
262264

263265
let mut total_constellations = 0;
264266
let mut total_moves = 0;
265-
eprintln!(
267+
info!(
266268
"{:>10} {:>10} {:>10} {:>10}",
267269
"boards", "moves", "deduped", "intersection"
268270
);
269-
eprintln!("-----------------------------------------------------");
271+
info!("-----------------------------------------------------");
272+
let mut round = Instant::now();
270273
for i in 1..(Board::SLOTS - 1) / 2 {
271274
let num_constellations = visited[i].len();
272275
let mut constellations: Vec<Board> = reverse_moves_par(&visited[i], threads);
276+
let rev_time = round.elapsed();
273277
let num_moves = constellations.len();
274278
#[cfg(not(target_arch = "wasm32"))]
275279
let start = Instant::now();
276280
constellations.fast_sort_unstable_mt(threads);
281+
let sort = start.elapsed();
277282
#[cfg(not(target_arch = "wasm32"))]
278283
{
279284
time_sort += start.elapsed();
280285
}
286+
let dd = Instant::now();
281287
let constellations = constellations.par_dedup(threads);
288+
let dd = dd.elapsed();
282289
let deduped = constellations.len();
283-
eprintln!(
284-
"{num_constellations:>10} {num_moves:>10} {deduped:>10} ({:.1}%)",
285-
deduped as f64 / num_moves as f64 * 100.
286-
);
287290
visited.push(constellations);
288291
total_moves += num_moves;
289292
total_constellations += deduped;
293+
let now = Instant::now();
294+
let rt = now - round;
295+
round = now;
296+
info!(
297+
"{num_constellations:>10} {num_moves:>10} {deduped:>10} ({:.1}%) {:>10?} (r: {:>10?}, s: {:>10?}, d: {:>10?})",
298+
deduped as f64 / num_moves as f64 * 100.,
299+
rt,
300+
rev_time,
301+
sort,
302+
dd,
303+
);
290304
}
291305
#[cfg(not(target_arch = "wasm32"))]
292306
let reverse_step = Instant::now();
@@ -301,25 +315,39 @@ pub fn calculate_all_solutions(threads: Option<NonZero<usize>>) -> Vec<Board> {
301315
#[cfg(not(target_arch = "wasm32"))]
302316
let invert_step = Instant::now();
303317

318+
let mut round = Instant::now();
304319
for remaining in (2..=(Board::SLOTS - 1) / 2 + 1).rev() {
305320
let num_constellations = visited[remaining].len();
306321
let mut constellations = possible_moves_par(&visited[remaining], threads);
322+
let t_moves = Instant::now();
323+
let d_moves = t_moves.duration_since(round);
307324
let num_moves = constellations.len();
308325
total_moves += num_moves;
309326
#[cfg(not(target_arch = "wasm32"))]
310327
let start = Instant::now();
311328
constellations.fast_sort_unstable_mt(threads);
329+
let t_sort = Instant::now();
330+
let d_sort = t_sort.duration_since(t_moves);
312331
let deduped = constellations.len();
313332
#[cfg(not(target_arch = "wasm32"))]
314333
{
315334
time_sort += start.elapsed();
316335
}
317336
visited[remaining - 1] = intersect_sorted_vecs(&visited[remaining - 1], &constellations);
337+
let t_intersect = Instant::now();
338+
let d_intersect = t_intersect.duration_since(t_sort);
318339
let intersection = visited[remaining - 1].len();
319-
eprintln!(
320-
"{num_constellations:>10} {num_moves:>10} {deduped:>10} ({:.1}%) {intersection:>10} ({:.1}%)",
340+
let now = Instant::now();
341+
let rt = now - round;
342+
round = now;
343+
info!(
344+
"{num_constellations:>10} {num_moves:>10} {deduped:>10} ({:.1}%) {intersection:>10} ({:.1}%) {:>10?} (m: {:>10?}, s: {:>10?}, i: {:>10?})",
321345
deduped as f64 / num_moves as f64 * 100.,
322346
intersection as f64 / deduped as f64 * 100.,
347+
rt,
348+
d_moves,
349+
d_sort,
350+
d_intersect,
323351
);
324352
}
325353
#[cfg(not(target_arch = "wasm32"))]
@@ -333,24 +361,24 @@ pub fn calculate_all_solutions(threads: Option<NonZero<usize>>) -> Vec<Board> {
333361
#[cfg(not(target_arch = "wasm32"))]
334362
let collect_step = Instant::now();
335363
assert_eq!(solvable.len(), 1679072);
336-
eprintln!("analyzed {total_moves} moves and {total_constellations} different constellations");
364+
info!("analyzed {total_moves} moves and {total_constellations} different constellations");
337365
#[cfg(not(target_arch = "wasm32"))]
338366
{
339-
eprintln!("reverse step: {:?}", reverse_step.duration_since(start));
340-
eprintln!(
367+
info!("reverse step: {:?}", reverse_step.duration_since(start));
368+
info!(
341369
" invert step: {:?}",
342370
invert_step.duration_since(reverse_step)
343371
);
344-
eprintln!(
372+
info!(
345373
"forward step: {:?}",
346374
forward_step.duration_since(invert_step)
347375
);
348-
eprintln!(
376+
info!(
349377
"collect step: {:?}",
350378
collect_step.duration_since(forward_step)
351379
);
352-
eprintln!(" total: {:?}", collect_step.duration_since(start));
353-
eprintln!(" sorting: {time_sort:?}");
380+
info!(" total: {:?}", collect_step.duration_since(start));
381+
info!(" sorting: {time_sort:?}");
354382
}
355383
solvable
356384
}

0 commit comments

Comments
 (0)