diff --git a/README.md b/README.md index 1ff2cd7..e0ef177 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ brew install tasnimAlam/word-counter/word_counter ## Usage ```console -$ ./word_counter poem.txt --top 4 --search lover +$ ./word_counter poem.txt --top 4 --search lover --max --duration +---------------+-------+---+ | Search result | lover | 3 | +---------------+-------+---+ @@ -44,6 +44,7 @@ $ ./word_counter poem.txt --top 4 --search lover +-------+-------+ | lover | 3 | +-------+-------+ +Duration : 2ms ``` ## Options @@ -56,10 +57,11 @@ USAGE: word_counter [FLAGS] [OPTIONS] FLAGS: - -h, --help Prints help information - -r, --reverse Reverse order - -m, --max Show most counted word - -V, --version Prints version information + -d, --duration Duration of all the calculations + -h, --help Prints help information + -r, --reverse Reverse order + -m, --max Show most counted word + -V, --version Prints version information OPTIONS: -o, --output Output file diff --git a/src/lib.rs b/src/lib.rs index 8acf428..d7d5e23 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,7 @@ use std::error::Error; use std::fs::File; use std::io::prelude::*; use std::path::PathBuf; +use std::time::Instant; use structopt::StructOpt; #[macro_use] extern crate prettytable; @@ -38,12 +39,17 @@ pub struct Opt { #[structopt(short = "m", long = "--max")] show_max: bool, + /// Duration of all the calculations + #[structopt(short = "d", long = "--duration")] + duration: bool, + /// Output file #[structopt(short, long, parse(from_os_str))] output: Option, } pub fn run(opt: Opt) -> Result<(), Box> { + let time = Instant::now(); // Read contents from file let mut f = File::open(opt.input)?; let mut contents = String::new(); @@ -90,6 +96,11 @@ pub fn run(opt: Opt) -> Result<(), Box> { // Print count table print_counts(&result); + // Print program duration + if opt.duration { + println!("Duration : {}ms", time.elapsed().as_millis()); + } + Ok(()) }