add timing option

This commit is contained in:
Magnus Ulimoen 2020-04-08 20:04:12 +02:00
parent e395c9c740
commit d174ac4854
1 changed files with 15 additions and 0 deletions

View File

@ -275,6 +275,9 @@ struct Options {
/// Number of outputs to save /// Number of outputs to save
#[structopt(long, short)] #[structopt(long, short)]
number_of_outputs: Option<u64>, number_of_outputs: Option<u64>,
/// Print the time to complete, taken in the compute loop
#[structopt(long)]
timings: bool,
} }
fn main() { fn main() {
@ -354,6 +357,13 @@ fn main() {
let mut output = OutputThread::new(output); let mut output = OutputThread::new(output);
let bar = progressbar(opt.no_progressbar, ntime); let bar = progressbar(opt.no_progressbar, ntime);
let timer = if opt.timings {
Some(std::time::Instant::now())
} else {
None
};
for itime in 0..ntime { for itime in 0..ntime {
if should_output(itime) { if should_output(itime) {
output.add_timestep(itime, &sys.fnow); output.add_timestep(itime, &sys.fnow);
@ -363,6 +373,11 @@ fn main() {
} }
bar.finish(); bar.finish();
if let Some(timer) = timer {
let duration = timer.elapsed();
println!("Time elapsed: {} seconds", duration.as_secs_f64());
}
output.add_timestep(ntime, &sys.fnow); output.add_timestep(ntime, &sys.fnow);
} }