hen 0.8.0

Run API collections from the command line.
use crate::request::Request;

use std::{io::{self, Write}, time::{Duration, Instant}};

pub async fn benchmark(mut request: Request, count: usize) {
    println!("Benchmarking request: {}", request.description);

    // remove the callback_src from the request
    request.callback_src = vec![];

    let mut request_time: Vec<Duration> = vec![];

    for i in 0..count {
        let start = Instant::now();
        request.clone().exec().await.unwrap();
        let duration = start.elapsed();
        request_time.push(duration);

        // prints a progress bar
        let progress = (i as f64 / (count - 1) as f64) * 100.0;
        print!("\r[");
        for j in 0..50 {
            if j as f64 / 50.0 <= progress / 100.0 {
                print!("#");
            } else {
                print!(" ");
            }
        }
        print!("] {:.2}%", progress);

        // flush the output
        io::stdout().flush().unwrap();
    }

    // calculate the mean duration and variance
    let mean_duration = request_time.iter().sum::<Duration>() / count as u32;
    let variance = request_time.iter().map(|x| (x.as_secs_f64() - mean_duration.as_secs_f64()).powi(2)).sum::<f64>() / count as f64;

    println!("\n");
    println!("Mean Duration: {:?}", mean_duration);
    println!("Variance (%): {:?}", variance * 100.0);
}