Skip to content

Commit

Permalink
Formatting and TODO added.
Browse files Browse the repository at this point in the history
  • Loading branch information
elfsternberg committed Aug 7, 2019
1 parent 36be043 commit 04d215d
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 129 deletions.
15 changes: 15 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
* Add a code of conduct.
* Clean up lib.rs.
* Make single & multi-threaded build options
* Document these options in the Makefile!
* Figure out why docs generation is twonky / broken
* Register with Cargo?
* Is there a cargo plug-in to run a fileserving webserver for your local
docs package?
* Break the trie into its own project? Probably not advisable, but did
it for the fsbitmaps
* Register fsbitmaps with Cargo?
* Replace the nested `for` loops with an ndrange iterator (see alt
project `ndrange`.)
* Register ndrange with Cargo!

104 changes: 57 additions & 47 deletions benches/perf1.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#[macro_use]
extern crate criterion;

use criterion::Criterion;
use criterion::black_box;
use criterion::Criterion;

use boggle_solver::{Board, solve, solve_mt};
use boggle_solver::dict::dict;
use boggle_solver::{solve, solve_mt, Board};

fn sample_to_vecs(arr: &[&[char]]) -> Vec<Vec<char>> {
let mut res = Vec::new();
Expand All @@ -21,63 +21,73 @@ fn sample_to_vecs(arr: &[&[char]]) -> Vec<Vec<char>> {

fn single_thread_standard_board(c: &mut Criterion) {
let trie = dict("/usr/share/dict/words");
c.bench_function("Single_threaded, standard_board", move |b| b.iter(|| {
let sample = sample_to_vecs(&[
&['m', 'a', 'p', 'o'],
&['e', 't', 'e', 'r'],
&['d', 'e', 'n', 'i'],
&['l', 'd', 'h', 'c'],
]);
let board = Board::new(sample, &trie).unwrap();
let _result = solve(&board);
}));
c.bench_function("Single_threaded, standard_board", move |b| {
b.iter(|| {
let sample = sample_to_vecs(&[
&['m', 'a', 'p', 'o'],
&['e', 't', 'e', 'r'],
&['d', 'e', 'n', 'i'],
&['l', 'd', 'h', 'c'],
]);
let board = Board::new(sample, &trie).unwrap();
let _result = solve(&board);
})
});
}

fn two_threads_standard_board(c: &mut Criterion) {
let trie = dict("/usr/share/dict/words");
c.bench_function("Two_Threads, standard_board", move |b| b.iter(|| {
let sample = sample_to_vecs(&[
&['m', 'a', 'p', 'o'],
&['e', 't', 'e', 'r'],
&['d', 'e', 'n', 'i'],
&['l', 'd', 'h', 'c'],
]);
let board = Board::new(sample, &trie).unwrap();
let _result = solve_mt(&board, 2);
}));
c.bench_function("Two_Threads, standard_board", move |b| {
b.iter(|| {
let sample = sample_to_vecs(&[
&['m', 'a', 'p', 'o'],
&['e', 't', 'e', 'r'],
&['d', 'e', 'n', 'i'],
&['l', 'd', 'h', 'c'],
]);
let board = Board::new(sample, &trie).unwrap();
let _result = solve_mt(&board, 2);
})
});
}

fn four_threads_standard_board(c: &mut Criterion) {
let trie = dict("/usr/share/dict/words");
c.bench_function("Four_threads, standard_board", move |b| b.iter(|| {
let sample = sample_to_vecs(&[
&['m', 'a', 'p', 'o'],
&['e', 't', 'e', 'r'],
&['d', 'e', 'n', 'i'],
&['l', 'd', 'h', 'c'],
]);
let board = Board::new(sample, &trie).unwrap();
let _result = solve_mt(&board, 4);
}));
c.bench_function("Four_threads, standard_board", move |b| {
b.iter(|| {
let sample = sample_to_vecs(&[
&['m', 'a', 'p', 'o'],
&['e', 't', 'e', 'r'],
&['d', 'e', 'n', 'i'],
&['l', 'd', 'h', 'c'],
]);
let board = Board::new(sample, &trie).unwrap();
let _result = solve_mt(&board, 4);
})
});
}

fn eight_threads_standard_board(c: &mut Criterion) {
let trie = dict("/usr/share/dict/words");
c.bench_function("Eight_threads, standard_board", move |b| b.iter(|| {
let sample = sample_to_vecs(&[
&['m', 'a', 'p', 'o'],
&['e', 't', 'e', 'r'],
&['d', 'e', 'n', 'i'],
&['l', 'd', 'h', 'c'],
]);
let board = Board::new(sample, &trie).unwrap();
let _result = solve_mt(&board, 8);
}));
c.bench_function("Eight_threads, standard_board", move |b| {
b.iter(|| {
let sample = sample_to_vecs(&[
&['m', 'a', 'p', 'o'],
&['e', 't', 'e', 'r'],
&['d', 'e', 'n', 'i'],
&['l', 'd', 'h', 'c'],
]);
let board = Board::new(sample, &trie).unwrap();
let _result = solve_mt(&board, 8);
})
});
}

criterion_group!(benches,
single_thread_standard_board,
two_threads_standard_board,
four_threads_standard_board,
eight_threads_standard_board);
criterion_group!(
benches,
single_thread_standard_board,
two_threads_standard_board,
four_threads_standard_board,
eight_threads_standard_board
);
criterion_main!(benches);
11 changes: 8 additions & 3 deletions src/bin/boggle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extern crate clap;
extern crate regex;

use boggle_solver::dict::dict;
use boggle_solver::{Board, solve};
use boggle_solver::{solve, Board};

use std::fs::File;
use std::io::{BufRead, BufReader, Write};
Expand Down Expand Up @@ -104,9 +104,14 @@ pub fn main() {
5 => 2,
6 => 3,
7 => 5,
_ => 11
_ => 11,
};
println!("{word:>width$}: {score}", word=s, width=17, score=score);
println!(
"{word:>width$}: {score}",
word = s,
width = 17,
score = score
);
tally += score
}
println!("\nTotal: {}", tally);
Expand Down
Loading

0 comments on commit 04d215d

Please sign in to comment.