diff --git a/Cargo.lock b/Cargo.lock index 43bf598..4908160 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -38,6 +38,7 @@ name = "aquatic_bench" version = "0.1.0" dependencies = [ "aquatic", + "indicatif", "mimalloc", "num-format", "plotly", @@ -97,6 +98,17 @@ dependencies = [ "toml", ] +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + [[package]] name = "autocfg" version = "1.0.0" @@ -128,6 +140,18 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +[[package]] +name = "clicolors-control" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90082ee5dcdd64dc4e9e0d37fbf3ee325419e39c0092191e0393df65518f741e" +dependencies = [ + "atty", + "lazy_static", + "libc", + "winapi", +] + [[package]] name = "cmake" version = "0.1.42" @@ -137,6 +161,22 @@ dependencies = [ "cc", ] +[[package]] +name = "console" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6728a28023f207181b193262711102bfbaf47cc9d13bc71d0736607ef8efe88c" +dependencies = [ + "clicolors-control", + "encode_unicode", + "lazy_static", + "libc", + "regex", + "termios", + "unicode-width", + "winapi", +] + [[package]] name = "const-random" version = "0.1.8" @@ -168,6 +208,12 @@ dependencies = [ "num_cpus", ] +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + [[package]] name = "env_logger" version = "0.7.1" @@ -213,6 +259,18 @@ dependencies = [ "autocfg", ] +[[package]] +name = "indicatif" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49a68371cf417889c9d7f98235b7102ea7c54fc59bcbd22f3dea785be9d27e40" +dependencies = [ + "console", + "lazy_static", + "number_prefix", + "regex", +] + [[package]] name = "itoa" version = "0.4.5" @@ -421,6 +479,12 @@ dependencies = [ "libc", ] +[[package]] +name = "number_prefix" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17b02fc0ff9a9e4b35b3342880f48e896ebf69f2967921fe8646bf5b7125956a" + [[package]] name = "plotly" version = "0.4.1" @@ -632,6 +696,15 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "termios" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0fcee7b24a25675de40d5bb4de6e41b0df07bc9856295e7e2b3a3600c400c2" +dependencies = [ + "libc", +] + [[package]] name = "thread_local" version = "1.0.1" @@ -650,6 +723,12 @@ dependencies = [ "serde", ] +[[package]] +name = "unicode-width" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" + [[package]] name = "unicode-xid" version = "0.2.0" diff --git a/TODO.md b/TODO.md index 1877cae..ce71f97 100644 --- a/TODO.md +++ b/TODO.md @@ -6,7 +6,6 @@ * Cleaner code * Stack-allocated vector? * Benchmarks - * Nicer progress output * Better black_box (or make sure to consume data) * Send in connect reponse ids to other functions as integration test diff --git a/aquatic_bench/Cargo.toml b/aquatic_bench/Cargo.toml index ae311fd..1fa1347 100644 --- a/aquatic_bench/Cargo.toml +++ b/aquatic_bench/Cargo.toml @@ -16,6 +16,7 @@ name = "plot_pareto" [dependencies] aquatic = { path = "../aquatic" } +indicatif = "0.14" mimalloc = "0.1" num-format = "0.4" plotly = "0.4" diff --git a/aquatic_bench/src/bin/bench_handlers/main.rs b/aquatic_bench/src/bin/bench_handlers/main.rs index 79edbbe..6530f29 100644 --- a/aquatic_bench/src/bin/bench_handlers/main.rs +++ b/aquatic_bench/src/bin/bench_handlers/main.rs @@ -10,6 +10,7 @@ use std::time::{Duration, Instant}; +use indicatif::{ProgressBar, ProgressStyle, ProgressIterator}; use num_format::{Locale, ToFormattedString}; use rand::{Rng, thread_rng, rngs::SmallRng, SeedableRng}; @@ -49,14 +50,23 @@ fn main(){ let mut announce_data = (0.0, 0.0); let mut scrape_data = (0.0, 0.0); + fn create_progress_bar(name: &str, iterations: u64) -> ProgressBar { + let t = format!("{:<16} {}", name, "{wide_bar} {pos:>2}/{len:>2}"); + let style = ProgressStyle::default_bar().template(&t); + + ProgressBar::new(iterations).with_style(style) + } + + println!("# Benchmarking request handlers\n"); + { let requests = connect::create_requests(); ::std::thread::sleep(Duration::from_secs(1)); - for round in 0..num_rounds { - println!("# Round {}/{}\n", round + 1, num_rounds); + let pb = create_progress_bar("Connect handler", num_rounds); + for _ in (0..num_rounds).progress_with(pb){ let d = connect::bench(requests.clone()); connect_data.0 += d.0; connect_data.1 += d.1; @@ -76,9 +86,9 @@ fn main(){ ::std::thread::sleep(Duration::from_secs(1)); - for round in 0..num_rounds { - println!("# Round {}/{}\n", round + 1, num_rounds); + let pb = create_progress_bar("Announce handler", num_rounds); + for round in (0..num_rounds).progress_with(pb) { let state = State::new(); let time = Time(Instant::now()); @@ -124,23 +134,20 @@ fn main(){ ::std::thread::sleep(Duration::from_secs(1)); - for round in 0..num_rounds { - println!("# Round {}/{}\n", round + 1, num_rounds); + let pb = create_progress_bar("Scrape handler", num_rounds); + for _ in (0..num_rounds).progress_with(pb) { let d = scrape::bench(&state, requests.clone()); scrape_data.0 += d.0; scrape_data.1 += d.1; - - println!(); } } + println!("\n## Average results over {} rounds\n", num_rounds); - println!("# Average results over {} rounds\n", num_rounds); - - print_results!("connect handler: ", num_rounds, connect_data); - print_results!("announce handler:", num_rounds, announce_data); - print_results!("scrape handler: ", num_rounds, scrape_data); + print_results!("Connect handler: ", num_rounds, connect_data); + print_results!("Announce handler:", num_rounds, announce_data); + print_results!("Scrape handler: ", num_rounds, scrape_data); } diff --git a/aquatic_bench/src/bin/bench_handlers/scrape.rs b/aquatic_bench/src/bin/bench_handlers/scrape.rs index b40af7f..3342153 100644 --- a/aquatic_bench/src/bin/bench_handlers/scrape.rs +++ b/aquatic_bench/src/bin/bench_handlers/scrape.rs @@ -25,8 +25,6 @@ pub fn bench( let now = Instant::now(); - println!("running benchmark.."); - handle_scrape_requests( &state, &mut responses,