introduced parallel processing of iterator with rayon
This commit is contained in:
33
src/main.rs
33
src/main.rs
@@ -1,5 +1,7 @@
|
||||
use clap::{Args, Parser, Subcommand};
|
||||
use text_correction::utils;
|
||||
use std::time::SystemTime;
|
||||
use std::process::*;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(name = "german word corrector")]
|
||||
@@ -13,7 +15,8 @@ struct Cli {
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
CorrectWord(WordArgs),
|
||||
CorrectFile(FileArgs)
|
||||
CorrectFile(FileArgs),
|
||||
BenchFile(FileArgs)
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
@@ -39,11 +42,35 @@ fn main() {
|
||||
|
||||
match &cli.command {
|
||||
Commands::CorrectWord(args) => {
|
||||
let out: String = utils::correct(args.input.clone(), args.list_path.clone());
|
||||
let out: String = utils::correct(args.input.clone(), args.list_path.as_str());
|
||||
println!("{}", out);
|
||||
},
|
||||
Commands::CorrectFile(args) => {
|
||||
utils::correct_file(args.input.clone(), args.list_path.clone(), args.output.clone())
|
||||
utils::correct_file_concurr(args.input.clone(), args.list_path.as_str(), args.output.clone())
|
||||
},
|
||||
Commands::BenchFile(args) => {
|
||||
let start_par = SystemTime::now();
|
||||
utils::correct_file_concurr(args.input.clone(), args.list_path.as_str(), args.output.clone());
|
||||
let stop_par = match start_par.elapsed() {
|
||||
Ok(elapsed) => elapsed.as_millis(),
|
||||
Err(e) => {
|
||||
println!("Error: {e:?}");
|
||||
exit(1);
|
||||
}
|
||||
};
|
||||
println!("Parallel processing took: {stop_par:?} ms");
|
||||
std::fs::remove_file(args.output.clone()).unwrap();
|
||||
let start = SystemTime::now();
|
||||
utils::correct_file(args.input.clone(), args.list_path.as_str(), args.output.clone());
|
||||
let stop = match start.elapsed() {
|
||||
Ok(elapsed) => elapsed.as_millis(),
|
||||
Err(e) => {
|
||||
println!("Error: {e:?}");
|
||||
exit(1);
|
||||
}
|
||||
};
|
||||
println!("Single-thread processing took: {stop:?} ms");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user